2011-12-14 29 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; 
} 

這可能不是一個完美的解決方案,但使用它時,有沒有更好的。