• I wanted to show the comments for each post on the index page but, after reading the codex and some posts on the forums, I really can’t work out how to make it work.

    For what I have read on the codex, a call to comments_template() inside the Loop should be enough to display the comments for each post, but this simply does nothing. Including the comments.php template directly results in the textarea for new comments being displayed, but again without showing the comments.

    I’m using the default template for WP1.5 for my tests:


    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="post">
    <h2 id="post-<?php the_ID(); ?>">" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></h2>
    <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>

    <div class="entry">
    <?php the_content('Read the rest of this entry »'); ?>
    </div>

    <p class="postmetadata">Posted in <?php the_category(', ') ?> | <?php edit_post_link('Edit','','|'); ?> <?php comments_popup_link('No Comments »', '1 Comment »', '% Comments »'); ?>

    <!-- ***** Comments should be displayed here: ***** -->
    <?php comments_template(); ?>

    <!--
    <?php trackback_rdf(); ?>
    -->
    </div>

    <?php endwhile; ?>

    I’ve been staring at the code for quite a while now, but still I can’t seem to make it work… any clues?

Viewing 2 replies - 1 through 2 (of 2 total)
  • comments_template() is extremely query-type aware, meaning it knows to display comments only at certain times, such as when you’re on a Page or single post. If you want comments on a post displayed anywhere else, you need to do one of two things:

    1. Duplicate the $comments query to the database along with much of comments.php where you want to display comments in your template.

    2. Edit the comments_template function found in wp-includes/comment-functions.php so it’s not so discriminating (as in editing down it’s initial if statement to test only on $withcomments).

    Thread Starter iret

    (@iret)

    Modifying comments_template() worked fine. Didn’t try to test it only on $withcomments as this would be in fact more discriminating: (A OR B OR C) is less discriminating than (C). Anyway, “if (true)” worked like a charm on the test, thank you very much for your help ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘comments_template() doesn’t work on index in WP1.5’ is closed to new replies.