comments_template() not working on main page
-
I’m trying to get comments to show on the index page of a site I’m creating – I’ve already set it to show only one post on the index page. And after searching the codex and forums, I’ve found that apparently what you need to do for that is to add
<?php comments_template() ?>
within the Loop.So I did that – at least, I hope that’s what I did – but it doesn’t appear to be working. Here is the code I have in my template (a rather heavily modified version of metamorph_killerwhale):
<?php while (have_posts()) { the_post(); $alternate=$i%2==0?"postentry1":"postentry2"; ?> <!-- start of post <?php the_title(); ?> --> <div id="page-<?php echo the_ID();?>" class="<?php echo $alternate;?>"> <p class="date2"><?php the_time('M') ?> <b><?php the_time('d') ?></b></p> <h4><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4><br /> <p class="categor"><strong>Posted:</strong> under <?php the_category(', ') ?>. <?php the_tags('Tags: ', ', ',''); ?><?php edit_post_link('[edit]',' | ',''); ?></p> <p class="post-body" style="display:none"><?php echo strip_tags(get_the_excerpt(), '<a><strong>'); ?> <a title="Permanent Link to <?php the_title(); ?>" href="<?php the_permalink() ?>" class="more">[...more]</a></p> <p class="post-body"><?php the_content('Read More', strip_teaser, 'more_file'); ?></p> <p class="date"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/comment.gif" alt="" /> <a href="<?php comments_link(); ?>" class="entryComment">Comments (<?php comments_number('0', '1', '%'); ?>)</a> </p> <!-- end of post <?php the_title(); ?> --> </div> <div id="comment"> <?php comments_template(); ?> </div> <br /><br /> <?php $i++; } ?>
I had previously put the comment div inside the div that immediately precedes it, but when that didn’t work I tried putting it outside, where you see it above – still no result. When I view source on the resulting page, I see the opening and closing div tag for the comment section, but with nothing in between them – so the
comments_template()
function doesn’t appear to be executing at all.Does anyone have any idea what might be going wrong here?
- The topic ‘comments_template() not working on main page’ is closed to new replies.