user9715356
user9715356

Reputation:

Comments not showing in WordPress - single.php appears not to be pulling through comments.php

I'm custom coding a WordPress theme. I have a single.php file and a comments.php file. I cannot get a comment form to appear on single.php, and I believe the problem is that it is not pulling through comments.php, because I put some dummy text in comments.php just to see what showed up and nothing at all changes on single.php no matter what I change on comments.php. I have made sure that comments are turned on in Discussion as well as on the individual posts. I have read and reread the documentation and tried the code several different ways. I've tried adding and subtracting code in functions.php and in the CSS. It's been weeks now, and I just don't know what else to try.

I've tried implementing solutions that others have posted, such as changing to and . There is no change to what displays on the single post page. I have also tried deactivating plugins, no effect.

Currently, my single.php is set up like this:

<?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(); ?>

I have also tried:

<?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(); ?>

I've also tried it without the while part, just starting from the if statement, and I've also tried putting the while loop around before the opening h2 tag, no change.

My expectation is that the comment form would appear below the share buttons, or at least the dummy text in my comments.php file, but there's nothing there at all.

Upvotes: 1

Views: 1212

Answers (1)

Nilambar Sharma
Nilambar Sharma

Reputation: 1740

You are not using loop properly. the_title(), the_content(), etc are supposed to be inside the loop and also the 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(); ?>

Upvotes: 0

Related Questions