Wordpress archive list with year, month, days, posts and comment counts
archive, wordpress
Solution
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:
Every post list:
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 years
foreach ($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 -->
Problem
I am willing to achieve a Wordpress archive list that would be like this: 2013 May (2) 04 - I love Wordpress (3 comments) 01 - I really love Wordpress (1 comment) February (1) 02 - Do I love Wordpress? 2012 ... From what I read elsewhere I have to create my own query. I am not really what one may call a developer. Here's what I started with: ``` <ul> <?php $args=array( 'post_type' => 'post', 'posts_per_page' => '500', /*no limit, how?*/ 'orderby' => 'date', 'order' => 'DESC', ); query_posts($args); while (have_posts()) : the_post(); ?> <li><?php the_time('j'); ?> | <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php comments_number( '', '(1)', '(%)' ); ?></li> <?php endwhile; ?> </ul> ``` You can see what it looks like here: http://www.vie-nomade.com/archives/ I know need to separate everything by month, then by year. Thanks.