Wordpress archive list with year, month, days, posts and comment counts Wordpress archive list with year, month, days, posts and comment counts wordpress wordpress

Wordpress archive list with year, month, days, posts and comment counts


You may want to consider performance issues related to query all your published posts.

I got a similar list, but displaying only the number of posts in each month, in total, I got 70 queries to the db, if I change it to display every post I got in that blog, the number goes up to 531 queries. (including other funcionality on the site, of course)

Montly list:showing how many post per month

Every post list:with every published post

If you decide to go with the monthly list, you can use wp_get_archives.

[/end of warning]

If don't write that much and only got a few posts, you should look for something like this:

<ul class="years"><?php$all_posts = get_posts(array(  'posts_per_page' => -1 // to show all posts));// this variable will contain all the posts in a associative array// with three levels, for every year, month and posts.$ordered_posts = array();foreach ($all_posts as $single) {  $year  = mysql2date('Y', $single->post_date);  $month = mysql2date('F', $single->post_date);  // specifies the position of the current post  $ordered_posts[$year][$month][] = $single;}// iterates the yearsforeach ($ordered_posts as $year => $months) { ?>  <li>    <h3><?php echo $year ?></h3>    <ul class="months">    <?php foreach ($months as $month => $posts ) { // iterates the moths ?>      <li>        <h3><?php printf("%s (%d)", $month, count($months[$month])) ?></h3>        <ul class="posts">          <?php foreach ($posts as $single ) { // iterates the posts ?>            <li>              <?php echo mysql2date('j', $single->post_date) ?> <a href="<?php echo get_permalink($single->ID); ?>"><?php echo get_the_title($single->ID); ?></a>  (<?php echo $single->comment_count ?>)</li>            </li>          <?php } // ends foreach $posts ?>        </ul> <!-- ul.posts -->      </li>    <?php } // ends foreach for $months ?>    </ul> <!-- ul.months -->  </li> <?php} // ends foreach for $ordered_posts?></ul><!-- ul.years -->