在过去的几个小时里我一直在解决这个问题,但无法找出原因,也无法在网上找到任何帮助。
基本上,我正在从头开始制作一个自定义主题。WordPress 总是以默认的“Hello world!”开始。帖子以及与该帖子关联的默认评论。
“世界你好!” post 不应评估为 false,但由于某种原因它确实如此。正如你所看到的,我尝试使用 WordPress 提供的 comments_templates 函数来允许从名为“comments.php”的文件运行代码,但这只是给我的问题添加了一个错误因素,并且这样做,“comments.php”中的代码" 甚至从未被访问过,所以现在我将其排除在外。
<?php
if(have_posts()) : while(have_posts()) : the_post();
get_template_part('content', get_post_format());
// comments_template('/comments.php', true);
if(have_comments()) :
echo 'OMG COMMENTS WORK';
foreach (get_comments() as $comment) :
echo $comment -> comment_content;
echo $comment -> comment_author;
echo apply_filters('comment_text', $comment -> comment_content);
endforeach;
else :
echo 'There are no comments to display here (this statement may or may not be true...)';
endif;
endwhile; endif;
?>
Run Code Online (Sandbox Code Playgroud)