php - 如何防止PHP代码以粗体输出内容?
问题描述
在我的 WordPress 网站中,我创建了一个类别模板文件(存档文件),用于显示来自特定类别的所有帖子。代码工作正常,我得到了我需要的确切结果。但是,我的代码存在一些问题(我无法调查)。
模板文件输出 5 个帖子,前 2 个帖子的内容正是它们的内容。但是,剩下的3篇帖子的内容却以粗体显示,很奇怪。
这是我的代码:
<section class="video_categories" id="content" style="float:left;">
<?php
$args = array(
'post_type' => 'post',
'category_name' => 'sponsor-spotlight',
'posts_per_page' => -1
);
$obituary_query = new WP_Query($args);
while ($obituary_query->have_posts()) : $obituary_query->the_post();
$readMore = '<a href="' . get_the_permalink() . '"> Keep On Reading...</a>';
echo '<div class="advert-div" style="padding-bottom: 15px;">'; ?>
<h2 class="ad-title"> <?php echo '<a style="color: #333333;font-weight: 600;" href="' . get_the_permalink() . '">';?> <?php the_title(); echo '</a>'; ?>
</h2>
<?php
$post = get_post( $post->ID );
$content_arr = get_extended($post->post_content);
echo apply_filters('the_content', $content_arr['main']);
echo $readMore;
echo '</div><hr>';
endwhile;
wp_reset_postdata();
?>
</section>
根据我的调查,问题在于以下代码行,因为它会导致输出<strong> </strong>
包含内容的标签:
$content_arr = get_extended($post->post_content);
echo apply_filters('the_content', $content_arr['main']);
因为当我这样做时:
echo apply_filters('the_content', $post->post_content);
<strong></strong>
我在前端看不到包含内容的任何标签。
这是我上面使用的代码的奇怪输出。
任何帮助将不胜感激!
解决方案
尽管代码没有理由<strong></strong>
在前端输出标签,所以我通过更改以粗体显示的每个帖子的状态来练习@Jayr 建议。问题在于这些帖子的内容。我只是重新创建了具有相同内容的新帖子,我的问题得到了解决。
感谢@Jayr 的快速回复!
推荐阅读
- javascript - 从按钮单击事件中调用 Codebehind 中的 Javascript 函数
- typescript - 打字稿编译错误:
不可分配给类型 - powershell - 使用powershell远程删除通配符文件夹中的多个注册表项?
- java - Java,Spring:创建单独的数据源 bean 抛出 NonUnique 错误
- php - 如何获取从下拉菜单中选择的选项并将其插入到mysql表中
- google-chrome-extension - 有没有办法在韩国销售 Chrome 扩展程序?
- maven - 在主服务项目中构建包括另一个项目的 WebContent 的战争
- spring - 我正在将 spring 与 jsf 集成,并且出现以下异常
- mysql - sql 转储不在 docker-compose 中运行
- jquery - 无论设备分辨率如何,div 的一致行为