评论未在 WordPress 中显示 - single.php 似乎没有通过 comments.php
Comments not showing in WordPress - single.php appears not to be pulling through comments.php
我正在自定义编码 WordPress 主题。我有一个 single.php 文件和一个 comments.php 文件。我无法在 single.php 上显示评论表单,我认为问题在于它没有通过 comments.php,因为我在 comments.php 中放置了一些虚拟文本只是为了查看显示的内容无论我在 comments.php 上做了什么更改,single.php 上都没有任何变化。我已确保在讨论以及个人 post 中打开评论。我已经阅读并重读了文档并尝试了几种不同的代码。我已经尝试在 functions.php 和 CSS 中添加和减去代码。现在已经好几个星期了,我只是不知道还能尝试什么。
我已经尝试实施其他人 posted 的解决方案,例如更改为 和 。单个 post 页面上显示的内容没有变化。我也试过停用插件,没有效果。
目前,我的 single.php 是这样设置的:
<?php get_header(); ?>
<!-- Post Start -->
<div class="postContainer">
<div class="ftImg"><?php the_post(); the_post_thumbnail(); ?>
</div>
<div class="post">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php the_post(); the_content(); ?>
</p>
<p>
<a class="readbtn" href="#">Back to the Blog</a>
</p>
<p>
<?php echo sharethis_inline_buttons(); ?>
</p>
<?php comments_template(); ?>
</div>
<?php get_footer(); ?>
我也试过:
<?php get_header(); ?>
<!-- Post Start -->
<div class="postContainer">
<div class="ftImg"><?php the_post(); the_post_thumbnail(); ?>
</div>
<div class="post">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php the_post(); the_content(); ?>
</p>
<p>
<a class="readbtn" href="#">Back to the Blog</a>
</p>
<p>
<?php echo sharethis_inline_buttons(); ?>
</p>
<?php while ( have_posts() ) : the_post();
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; ?>
</div>
<?php get_footer(); ?>
我也试过没有 while 部分,只是从 if 语句开始,我也试过将 while 循环放在开始的 h2 标记之前,没有改变。
我的期望是评论表单会出现在共享按钮下方,或者至少是我的 comments.php 文件中的虚拟文本,但那里什么也没有。
您没有正确使用循环。 the_title()
、the_content()
等应该在循环内,comments_template()
也应该在循环内。
<!-- Post Start -->
<div class="postContainer">
<div class="ftImg"><?php the_post_thumbnail(); ?></div>
<?php
while ( have_posts() ) :
the_post();
?>
<div class="post">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php the_content(); ?>
</p>
<p>
<a class="readbtn" href="#">Back to the Blog</a>
</p>
<?php comments_template(); ?>
</div>
<?php endwhile; // end of the loop. ?>
</div>
<?php get_footer(); ?>
我正在自定义编码 WordPress 主题。我有一个 single.php 文件和一个 comments.php 文件。我无法在 single.php 上显示评论表单,我认为问题在于它没有通过 comments.php,因为我在 comments.php 中放置了一些虚拟文本只是为了查看显示的内容无论我在 comments.php 上做了什么更改,single.php 上都没有任何变化。我已确保在讨论以及个人 post 中打开评论。我已经阅读并重读了文档并尝试了几种不同的代码。我已经尝试在 functions.php 和 CSS 中添加和减去代码。现在已经好几个星期了,我只是不知道还能尝试什么。
我已经尝试实施其他人 posted 的解决方案,例如更改为 和 。单个 post 页面上显示的内容没有变化。我也试过停用插件,没有效果。
目前,我的 single.php 是这样设置的:
<?php get_header(); ?>
<!-- Post Start -->
<div class="postContainer">
<div class="ftImg"><?php the_post(); the_post_thumbnail(); ?>
</div>
<div class="post">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php the_post(); the_content(); ?>
</p>
<p>
<a class="readbtn" href="#">Back to the Blog</a>
</p>
<p>
<?php echo sharethis_inline_buttons(); ?>
</p>
<?php comments_template(); ?>
</div>
<?php get_footer(); ?>
我也试过:
<?php get_header(); ?>
<!-- Post Start -->
<div class="postContainer">
<div class="ftImg"><?php the_post(); the_post_thumbnail(); ?>
</div>
<div class="post">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php the_post(); the_content(); ?>
</p>
<p>
<a class="readbtn" href="#">Back to the Blog</a>
</p>
<p>
<?php echo sharethis_inline_buttons(); ?>
</p>
<?php while ( have_posts() ) : the_post();
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; ?>
</div>
<?php get_footer(); ?>
我也试过没有 while 部分,只是从 if 语句开始,我也试过将 while 循环放在开始的 h2 标记之前,没有改变。
我的期望是评论表单会出现在共享按钮下方,或者至少是我的 comments.php 文件中的虚拟文本,但那里什么也没有。
您没有正确使用循环。 the_title()
、the_content()
等应该在循环内,comments_template()
也应该在循环内。
<!-- Post Start -->
<div class="postContainer">
<div class="ftImg"><?php the_post_thumbnail(); ?></div>
<?php
while ( have_posts() ) :
the_post();
?>
<div class="post">
<h2>
<?php the_title(); ?>
</h2>
<p>
<?php the_content(); ?>
</p>
<p>
<a class="readbtn" href="#">Back to the Blog</a>
</p>
<?php comments_template(); ?>
</div>
<?php endwhile; // end of the loop. ?>
</div>
<?php get_footer(); ?>