开发者

Limiting the list of archives in wordpress based on date

开发者 https://www.devze.com 2022-12-29 03:35 出处:网络
I am using wordpress and I am displaying my archives list in a sidebar using the function 开发者_如何学Python

I am using wordpress and I am displaying my archives list in a sidebar using the function

开发者_如何学Python

wp_get_archives('type=monthly');

I have posts from Feb 2005 to April 2010 but I want to display June 2009 onwards links. (i.e. june 2009, july 2009, ....april 2010).

How do I prevent Feb 2005 - may 2005 from being displayed in the archives list.

(Please don't suggest adding a limit i.e. wp_get_archives('type=daily&limit=15'); . That will not solve my problem)


$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>";
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号