Wordpress自定义帖子类型年度/月度档案

时间:2010-09-26 14:33:17

标签: wordpress custom-post-type

有没有在wordpress中有自定义帖子类型的年度或月度档案? 我搜索得无处不在。 我会想象网址结构是这样的:

http://sitename/custom-post-type/year/month

任何?

2 个答案:

答案 0 :(得分:0)

我的插件Custom Post Permalinks可让您调整永久链接设置。但是,截至目前,它仅适用于非分层帖子类型。我正在开发一个允许这两种类型的新版本。

答案 1 :(得分:0)

您可以尝试使用此代码。用您的CPT名称替换阵列中的CPT。

此功能将转换以下网址

  

http://example.net/CPT/2016/06

  

http://example.net/?post_type=CPT&m=201606

实际上是由wordpress使用的。

add_action('init', 'date_cpt_rewrites');

function date_cpt_rewrites() {
    $custom_post_types = array('CPT'); //some example post types
    foreach ( $custom_post_types as $post_type ) {
        $rule = '^' . $post_type . '/(\d+)/(\d+)/?$';
        $rewrite = 'index.php?post_type=' . $post_type . '&m=$matches[1]$matches[2]';
        add_rewrite_rule($rule,$rewrite,'top');
    }


}
相关问题