我正在自定义编码WordPress主题。我有一个single.php文件和一个comment.php文件。我无法将评论表单显示在single.php上,并且我认为问题在于它没有通过comments.php,因为我在comment.php中放置了一些虚拟文本,只是为了查看显示的内容而没有任何更改在single.php上,无论我对comment.php进行什么更改。我确保在“讨论”以及各个帖子中都打开了评论。我已经阅读并重新阅读了文档,并以几种不同的方式尝试了代码。我试过在functions.php和CSS中添加和减去代码。已经有几个星期了,我只是不知道还能尝试什么。
我尝试实施其他人发布的解决方案,例如更改为和。单个帖子页面上显示的内容没有变化。我也尝试过停用插件,没有效果。
当前,我的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文件中的虚拟文本下,但根本没有。
答案 0 :(得分:0)
您没有正确使用循环。 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(); ?>