WordPress.org

Forums

[resolved] Display comments on each post in category (9 posts)

  1. atmeurer
    Member
    Posted 2 years ago #

    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:

    <?php
    $wp_query->is_single = true;
    comments_template();
    $wp_query->is_single = false;
    ?>

    and

    <?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; ?>
    
    			</h1>
    
        <?php
    						/* 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>
        <div class="alignright">
          <?php previous_posts_link('Newer Entries') ?>
        </div>
      </div>
      <?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; ?>
    </div>
      <?php get_sidebar(); ?>
    <!-- /content -->
    <?php get_footer(); ?>
  2. robwasripped
    Member
    Posted 2 years ago #

    Hi,

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

  3. atmeurer
    Member
    Posted 2 years ago #

    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!

  4. Michael
    Forum Moderator
    Posted 2 years ago #

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

    what theme are you using?

  5. atmeurer
    Member
    Posted 2 years ago #

  6. Michael
    Forum Moderator
    Posted 2 years ago #

    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;

    example:

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

  7. atmeurer
    Member
    Posted 2 years ago #

    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 /> ') ?>
          </p>
          <p>
            <?php the_tags('TAG:<br />', ' <br /> ' , ''); ?>
          </p>
          <p> <p>COMMENTS:<br /><?php comments_popup_link('No Comments »','1 Comment »','% Comments »', '','Comments Closed' ); ?>
    </p>
    
              <p>        <?php edit_post_link('Edit ', '', ''); ?>
    </p>
        </div>
        <div class="righttext">
          <h2 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>">
            <?php the_title(); ?>
            </a></h2>
    
          <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
          </a>
          <?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>
    
        </div>
        <div class="cb"></div>
      </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.

  8. Michael
    Forum Moderator
    Posted 2 years ago #

    I am quoting my earlier reply:

    the code should be within the loop
    review:
    http://codex.wordpress.org/The_Loop
    http://codex.wordpress.org/Theme_Development

    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):

    HERE
        </div>
    OR HERE
        <div class="cb"></div>
    OR HERE
      </div>
      <?php endwhile; ?>
  9. atmeurer
    Member
    Posted 2 years ago #

    That worked perfect... thanks for your help and patience :-)

Topic Closed

This topic has been closed to new replies.

About this Topic