2011-12-14 55 views
1

我需要列出按月划分在2011年的所有帖子,我会做这样的事情在WordPress(很简单的解释here):的WordPress:列出所有文章和集团通过他们与月年

query_posts('monthnum=12&year=2011'); 
while (have_posts()) : the_post(); 
    echo '<li>'; 
    the_title(); 
    echo '</li>'; 
endwhile; 

现在,如何列出所有帖子,并将它们组合按月年,不知道我应该走多远了?也就是说,我不知道哪一年是写入的最古老的帖子。从技术上讲,我可以试着做monthnum=12&year=2010,monthnum=12&year=2009等;但我觉得肯定有更好的办法。

+0

看这一个 - http://stackoverflow.com/a/8503565/691506 – inlanger 2011-12-15 11:01:12

回答

0

一种解决方案可能是遍历所有年份:

for($i=0;$i<10;$i++){ 
    $y=2011-$id; 
    query_posts("monthnum=12&year=$y"); 
    while (have_posts()) : the_post(); 
     echo '<li>'; 
     the_title(); 
     echo '</li>'; 
    endwhile; 
} 

这可能不是一个完美的解决方案,但使用它时,有没有更好的。