• Hi,

    I am trying to show comments underneath each post on the main index page of my blog.

    Searching the forum shows that i should put <?php comments_template(); ?> in my code before <?php endwhile; ?>
    .

    I have tried doing this and it is not working. Any ideas?

    My index code is below.

    Thanks.

    ‘<?php get_header();?>
    <?php get_sidebar();?>
    <div id=”content”>
    <?php if (have_posts()) : ?>

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

    <div class=”post” id=”post-<?php the_ID(); ?>”>
    <h1>” rel=”bookmark” title=”Permanent Link to <?php the_title_attribute(); ?>”><?php the_title(); ?></h1>

    <div class=”entry”>
    <?php the_content(); ?>
    </div>

    <div class=”postmetadata”><?php the_tags(‘Tags: ‘, ‘, ‘, ‘
    ‘); ?> Posted in <?php the_category(‘, ‘) ?> on <?php the_time(‘F j, Y’) ?> <!– | by <?php the_author() ?> –>| <?php edit_post_link(‘Edit’, ”, ‘ | ‘); ?> There are currently <?php comments_popup_link(‘No Comments’, ‘1 Comment’, ‘% Comments’); ?></div>

    </div>

    <?php endwhile; ?>

    <div class=”navigation”>
    <div class=”alignleft”><?php next_posts_link(‘« Older Entries’) ?></div>
    <div class=”alignright”><?php previous_posts_link(‘Newer Entries »’) ?></div>
    </div>

    <?php else : ?>

    <h2 class=”center”>Not Found</h2>
    <p class=”center”>Sorry, but you are looking for something that isn’t here.</p>
    <?php include (TEMPLATEPATH . “/searchform.php”); ?>

    <?php endif; ?>
    </div>
    <?php get_footer ();?>

    </body>
    </html>’

Viewing 1 replies (of 1 total)
  • I found this response elsewhere:

    https://clifgriffin.com/2008/10/28/display-comment-form-on-main-index-in-wordpress/

    As far as I can tell, something changed in the WordPress core code that prevents <?php comments_template(); ?> from working by itself on the Main Index page. You actually need two lines of code:

    <?php $withcomments = 1; ?>
    <?php comments_template(); ?>

    Again, you need to place it before the <?php endwhile; ?>, and in my experience, you need to place it before the last </div> or you’ll lose your formatting.

    The caveat is that this method basically recreates the whole Single Post section on the Main Index page, including the Comment box, whether or not there are previous comments. If you only expect to have a few comments on each post, and you can live with the Comment Box on the Main Page, it works fine.

Viewing 1 replies (of 1 total)
  • The topic ‘Show comments on main index page’ is closed to new replies.