WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to make a archive page template (11 posts)

  1. amit200635
    Member
    Posted 2 years ago #

    [ Moderator Note: Please post code or markup snippets between backticks or use the code button. ]

    How to make a archive page template to show all post listed by months with no of comments. currently i m using this one code for showing the month and post in that month. i need to show the no of comments too.. Plz Help Me

    <?php
    
    // Declare some helper vars
    $previous_year = $year = 0;
    $previous_month = $month = 0;
    $ul_open = false;
    
    // Get the posts
    $myposts = get_posts('numberposts=-1&orderby=post_date&order=DESC');
    
    ?>
    
    <?php foreach($myposts as $post) : ?>	
    
    	<?php
    
    	// Setup the post variables
    	setup_postdata($post);
    
    	$year = mysql2date('Y', $post->post_date);
    	$month = mysql2date('n', $post->post_date);
    	$day = mysql2date('j', $post->post_date);
    
    	?>
    
    	<?php if($year != $previous_year || $month != $previous_month) : ?>
    
    		<?php if($ul_open == true) : ?>
    
    		<?php endif; ?>
    
    		<h3 ><?php the_time('F Y'); ?></h3>
    
    		<ul class="month_archive" >
    
    		<?php $ul_open = true; ?>
    
    	<?php endif; ?>
    
    	<?php $previous_year = $year; $previous_month = $month; ?>
    
    <li><span class="the_day"><?php the_time('d') ?>:</span> <span class="the_article"><a
    href="<?php the_permalink(); ?>"><?php the_title(); ?></span></li>
    <?php endforeach; ?>

    Thanks in advance .

  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    i need to show the no of comments too..

    see:
    http://codex.wordpress.org/Function_Reference/comments_number

  3. amit200635
    Member
    Posted 2 years ago #

    where to put that code i dont know do u know sir?

    <?php comments_number( $zero, $one, $more ); ?>

  4. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    where do you want to show the comment number?

    if after the title, than add the code here, possibly within a span for formatting:

    <li><span class="the_day"><?php the_time('d') ?>:</span> <span class="the_article"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></span> <span class="comments_number"><?php comments_number(); ?></span></li>
  5. amit200635
    Member
    Posted 2 years ago #

    i have tried this one on my archive page template but its not working.
    any other idea or way to show the no of comments.

    Ty @ alchymyth

  6. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    the code is working in my test setup;

    possibly check your code as the posted version has a break within these lines:

    <li><span class="the_day"><?php the_time('d') ?>:</span> <span class="the_article"><a
    href="<?php the_permalink(); ?>"><?php the_title(); ?></span></li>

    should be:

    <li><span class="the_day"><?php the_time('d') ?>:</span> <span class="the_article"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></span></li>

    the try to re-apply the suggested code.

  7. amit200635
    Member
    Posted 2 years ago #

    Sorry Alchymyth Sir

    <li><span class="the_day"><?php the_time('d') ?>:</span> <span class="the_article"><a>"><?php the_title(); ?></span> (<span class="comments_number"><?php comments_number(); ?></span>)</a></li>
    the code is showing only the result "No comments" in all the posts while some posts have some comments.

    Ty

  8. amit200635
    Member
    Posted 2 years ago #

    sir can u see the comment no beside the post name on ur system?

  9. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    sir can u see the comment no beside the post name on ur system?

    yes - I saw various comments nummbers beside the post titles in my test setup.

    you could alternatively try to use 'get_comments_number()' which would just return a number;
    http://codex.wordpress.org/Template_Tags/get_comments_number

    code:

    <li><span class="the_day"><?php the_time('d') ?>:</span> <span class="the_article"><a>"><?php the_title(); ?></span> (<span class="comments_number"><?php echo get_comments_number($post->ID); ?></span>)</a></li>
  10. amit200635
    Member
    Posted 2 years ago #

    wow !!

    Finally it works...
    Ty Alchymyth Sir

  11. amit200635
    Member
    Posted 2 years ago #

    Ty for ur help sir.
    I m closing this post as resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic