【问题标题】:Custom Post Type monthly archive自定义帖子类型每月存档
【发布时间】:2014-02-19 14:06:50
【问题描述】:

我的functions.php中有以下代码:

function add_rewrite_rules($aRules) {
    $aNewRules = array(
        'news/([0-9]{4})/page/?([0-9]{1,})/?$' => 'index.php?post_type=news&year=$matches[1]&paged=$matches[2]',
        'news/([0-9]{4})/?$' => 'index.php?post_type=news&year=$matches[1]',
        'blog/([0-9]{4})/page/?([0-9]{1,})/?$' => 'index.php?post_type=blog&year=$matches[1]&paged=$matches[2]',
        'blog/([0-9]{4})/?$' => 'index.php?post_type=blog&year=$matches[1]'
    );
    $aRules = $aNewRules + $aRules;
    return $aRules;
}

add_filter('rewrite_rules_array', 'add_rewrite_rules');

这使我的永久链接像这样工作:

/blog

/blog/post-name

/blog/2014

我对代码的理解不够充分,无法将其调整为每月存档,例如:

/blog/2014/01

【问题讨论】:

    标签: php wordpress archive custom-post-type


    【解决方案1】:

    尝试添加

     'blog/([0-9]{4})/([0-9]{1,2})/?$' => 'index.php?post_type=blog&year=$matches[1]&monthnum=$matches[2]'
    

    到你的数组。

    【讨论】:

    • 它停止进入未找到的页面,但显示每个月的所有帖子而不是过滤它们
    • @CarlaDessi 现在试试,我编辑了答案。 (将月份更改为月份)
    • 现在找不到每个月的鞋子页面
    猜你喜欢
    • 2013-01-07
    • 2012-08-31
    • 2011-04-17
    • 1970-01-01
    • 1970-01-01
    • 2014-06-16
    • 2017-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多