Support » Fixing WordPress » How to make a archive page template

  • Resolved amit200635

    (@amit200635)


    [ 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 .

Viewing 10 replies - 1 through 10 (of 10 total)
  • Michael

    (@alchymyth)

    Forum Moderator

    i need to show the no of comments too..

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

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

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

    Michael

    (@alchymyth)

    Forum Moderator

    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>

    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

    Michael

    (@alchymyth)

    Forum Moderator

    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.

    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

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

    Michael

    (@alchymyth)

    Forum Moderator

    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>

    wow !!

    Finally it works…
    Ty Alchymyth Sir

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

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How to make a archive page template’ is closed to new replies.