为什么the_content在wordpress single.php中不起作用

我的代码:

< ?php if (have_posts()) : ?> < ?php while (have_posts()) : the_post(); ?> < div class="posts" id="post-< ?php the_ID(); ?> " < ?php post_class(); ?> > < h2> < ?php the_title(); ?> < /h2> < div class="entry"> < ?php the_content(); ?> < /div> < /div> < !--post end--> < ?php endwhile; ?> < ?php else : ?> < h3> no content< /h3> < ?php endif; ?>

我将代码放入自定义的wordpress主题文件single.php中。为什么不能输出帖子内容, 却可以输出帖子标题。谢谢。
#1你可以尝试以下方法来查看它是否代替the_content起作用
< ?php echo wpautop($post-> post_content); ?> // content with p tags < ?php echo $post-> post_content; ?> //without p tags

也是一个选择
< ?php echo wpautop( get_the_content() ); ?> // content with p tags

看看是否适合你。
#2在开发Wordpress主题时, 建议你将调试模式(在安装目录的wp-config.php中找到)切换为true。如果你有任何错误, 这将提醒你。
在你的情况下, 请尝试< ?php the_excerpt(); 。 ?> 。另外, 这听起来可能有些愚蠢, 但是你实际上有帖子吗?不是该帖子中的页面或内容?
#3很多时候, 我遇到过来自开发人员或首次主题开发人员的查询, 这些查询关于无法在其自定义模板页面上显示the_content()。问题是the_content()函数在WP循环内运行, 因此例如
if (have_posts()) { while (have_posts()) { the_post(); the_content(); } } ?>

【为什么the_content在wordpress single.php中不起作用】这将起作用, 但是在某些情况下, 你想在循环外调用该函数–解决方案是:
echo $post-> post_content;

    推荐阅读