限制基于日期在WordPress档案
问题描述:
我使用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');这不会解决我的问题)
答
$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>";