【问题标题】:Limiting the list of archives in wordpress based on date根据日期限制 wordpress 中的档案列表
【发布时间】:2010-05-06 10:36:34
【问题描述】:

我正在使用 wordpress 和 我正在使用该功能在侧边栏中显示我的档案列表

wp_get_archives('type=monthly');

我有 2005 年 2 月至 2010 年 4 月的帖子,但我想显示 2009 年 6 月以后的链接。 (即 2009 年 6 月、2009 年 7 月、....2010 年 4 月)。

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

(请不要建议添加限制,即 wp_get_archives('type=daily&limit=15'); 。这不会解决我的问题)

【问题讨论】:

    标签: wordpress archive


    【解决方案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>";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-20
      • 1970-01-01
      • 2022-11-28
      • 1970-01-01
      • 2013-07-01
      • 2021-11-26
      • 2011-02-25
      相关资源
      最近更新 更多