Support » Themes and Templates » Display comments on each post in category

  • Resolved atmeurer


    I have been searching how to edit the archive.php file so that in the categories, each post shows its comment section.

    I found scripts that put one comment section at the bottom of the page.. Like this:

    $wp_query->is_single = true;
    $wp_query->is_single = false;


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

    I dont know if i am just putting those in the wrong place on the page.. or if they just dont work for what i am trying.

    Here is the script contained in my archive.php file:

    <?php get_header(); ?>
    <div class="siglepage">
      <div class="index_top"></div>
      <div id="left">
      <?php if (have_posts()) : ?>
    			<h1 class="pagetitle">
    <?php if ( is_day() ) : ?>
    				<?php printf(  'Daily Archives: <span>%s</span>', get_the_date() ); ?>
    <?php elseif ( is_month() ) : ?>
    				<?php printf( 'Monthly Archives: <span>%s</span>', get_the_date('F Y') ); ?>
    <?php elseif ( is_year() ) : ?>
    				<?php printf(  'Yearly Archives: <span>%s</span>', get_the_date('Y') ); ?>
     <?php elseif ( is_author() ) : ?>
    				<?php printf( 'Author Archive'); ?>
     <?php elseif ( is_category() ) : ?>
    				<?php printf( 'Category Archive: <span>%s</span>',single_cat_title("", false)); ?>
     <?php elseif ( is_tag() ) : ?>
    				<?php printf( 'Tag Archive: <span>%s</span>',single_tag_title("", false)); ?>
    <?php else : ?>
    				Blog Archives
    <?php endif; ?>
    						/* Include the Post-Format-specific template for the content.
    						 * If you want to overload this in a child theme then include a file
    						 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
    						get_template_part( 'content', get_post_format() );
      <div class="navigation">
        <div class="alignleft">
          <?php next_posts_link('Older Entries') ?>
        <div class="alignright">
          <?php previous_posts_link('Newer Entries') ?>
      <?php else : ?>
      <h2 class="title2">Not Found</h2>
      <p class="aligncenter">Sorry, but you are looking for something that isn't here.</p>
      <?php get_search_form(); ?>
      <?php endif; ?>
      <?php get_sidebar(); ?>
    <!-- /content -->
    <?php get_footer(); ?>

Viewing 8 replies - 1 through 8 (of 8 total)
  • Hi,

    You need to call global $withcomments; before defining the variable.

    I am sorry, but i am limited in my ability.. could you show where that should go?

    also, just to clarify.. the scripts i mentioned above both worked.. just that they only showed 1 comments pane at the bottom of the page. i want a comments section at the bottom of each post. Thanks much for your help!

    the code should be within the loop, which in your case might be in content.php (?)

    what theme are you using?

    have you looked into content.php and tried to add the code there?

    you might need to wrap the code into a conditional statement to check that it is used in a category archive;


    <?php if( is_category() ) { global $withcomments; $withcomments = 1; comments_template(); } ?>

    here is the script from my content.php:

    <?php if( is_category() ) { global $withcomments; $withcomments = 1; comments_template(); } ?>
    <?php while (have_posts()) : the_post(); ?>
      <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
        <div class="leftinfo">
         <?php FloatingLight_datestyle();?>
          <p>Category:<br />
            <?php the_category('<br /> ') ?>
            <?php the_tags('TAG:<br />', ' <br /> ' , ''); ?>
          <p> <p>COMMENTS:<br /><?php comments_popup_link('No Comments »','1 Comment »','% Comments »', '','Comments Closed' ); ?>
              <p>        <?php edit_post_link('Edit ', '', ''); ?>
        <div class="righttext">
          <h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
            <?php the_title(); ?>
          <div class="entry">
          <?php if ( ( function_exists( 'get_post_format' ) && 'gallery' == get_post_format( $post->ID ) ) || in_category( 'gallery' ) ) : ?>
          <a href="<?php echo get_post_format_link( 'gallery' ); ?>" title="View Galleries">
         More Galleries
          <?php endif;?>
          <?php the_content('<span class="more">Read the rest of this entry >></span>'); ?>
          <?php wp_link_pages(array('before' => '<div class="page-link"><strong>Pages:</strong> ', 'after' => '</div>', 'next_or_number' => 'number')); ?>
        <div class="cb"></div>
      <?php endwhile; ?>

    Where do i add that line? I tried adding it at the top and got the same result.. one comments section at the top of the page and not under each post. Thanks.

    I am quoting my earlier reply:

    the code should be within the loop


    where exactly you put the code (within the loop) depends on where you want to have the comments and comment form for each post.

    try these locations (each might have a slight different effect on the layout):

        <div class="cb"></div>
      <?php endwhile; ?>

    That worked perfect… thanks for your help and patience 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Display comments on each post in category’ is closed to new replies.