【问题标题】:Comments not showing in WordPress - single.php appears not to be pulling through comments.phpWordPress 中未显示评论 - single.php 似乎没有通过 comments.php
【发布时间】:2019-04-22 16:53:50
【问题描述】:

我正在自定义编码 WordPress 主题。我有一个 single.php 文件和一个 cmets.php 文件。我无法在 single.php 上显示评论表单,我认为问题在于它没有通过 cmets.php,因为我在 cmets.php 中放置了一些虚拟文本,只是为了查看显示的内容而没有任何变化无论我在 cmets.php 上进行什么更改,都在 single.php 上。我已确保在讨论和个别帖子中打开 cmets。我已经阅读并重新阅读了文档,并尝试了几种不同的代码。我尝试在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标签之前,没有改变。

我的期望是评论表单会出现在分享按钮下方,或者至少是我的 cmets.php 文件中的虚拟文本,但那里什么都没有。

【问题讨论】:

    标签: wordpress wordpress-theming comments


    【解决方案1】:

    您没有正确使用循环。 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(); ?>
    

    【讨论】:

    • 谢谢!我实施了该解决方案,我的特色图片和页脚之间的所有内容都消失了,因此在此页面或其他地方我肯定做错了更多。是否有可能我的 functions.php 设置不正确,因为正确使用 while 循环会导致内容消失?
    • 再次评论以防其他人遇到此问题 - 一旦我包装了

      标签中,它起作用了!再次感谢!

    猜你喜欢
    • 1970-01-01
    • 2015-03-11
    • 1970-01-01
    • 2015-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多