我愿意实现一个Wordpress存档列表,如下所示:
2013
五月(2)
04 - 我喜欢Wordpress(3条评论)
01 - 我真的很喜欢Wordpress(1条评论)二月(1)
02 - 我喜欢Wordpress吗?
2012
...
从我在别处读到的内容,我必须创建自己的查询.我真的不是一个可以称之为开发者的人.这是我开始的:
<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>
Run Code Online (Sandbox Code Playgroud)
您可以在这里看到它的样子:http: //www.vie-nomade.com/archives/
我知道需要按月分类,然后按年分开.谢谢.
您可能需要考虑与查询所有已发布帖子相关的性能问题.
我有一个类似的列表,但是每个月只显示帖子的数量,总共有70个查询到数据库,如果我更改它以显示我在该博客中收到的每个帖子,该数字最多可达531个查询.(当然包括网站上的其他功能)
Montly列表:

每个帖子列表:

如果您决定使用月度列表,则可以使用wp_get_archives.
[/警告结束]
如果不写那么多,只有几个帖子,你应该寻找这样的东西:
<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 -->
Run Code Online (Sandbox Code Playgroud)