2010-05-06 56 views
0

我使用WordPress和 我使用的功能限制基於日期在WordPress檔案

wp_get_archives(「類型=每月」)顯示在側邊欄我的檔案名單之列;

我有帖子從2005年2月到2010年4月,但我想顯示2009年6月以後的鏈接。 (即2009年6月,2009年7月,...... 2010年4月)。

如何防止2005年2月 - 2005年5月顯示在檔案列表中。

(請不要建議增加一個限制,即wp_get_archives( '類型=每日&上限= 15');這不會解決我的問題)

回答

1
$args = array(
    'type'   => 'monthly', 
    'format'   => 'custom', 
    'show_post_count' => true, 
    'echo'   => 0); 
$resulthtml = wp_get_archives($args); 
$links_to_archives = array_map('trim', explode("\n", $resulthtml)); 
$string_in_first_archive_not_wanted = 'May 2005'; 

// wp_get_archives works in reverse order 
print "<ul>"; 
foreach($links_to_archives as $link) { 
    // once we hit 'May 2005' we don't print anything more 
    if (strpos($link, $string_in_first_archive_not_wanted) > 0) { 
     break; 
    } else { 
     print "<li>" . $link . "</li>"; 
    } 
} 
print "</ul>";