【问题标题】:Wordpress custom post type yearly/monthly archivesWordPress 自定义帖子类型每年/每月档案
【发布时间】:2011-04-17 10:16:31
【问题描述】:

在 wordpress 中是否有自定义帖子类型的年度或每月存档? 我已经四处寻找无济于事。 我会想象 url 结构是这样的:

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

有人吗?

【问题讨论】:

标签: wordpress custom-post-type


【解决方案1】:

你可以试试这个代码。将数组中的 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');
    }


}

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 2013-01-07
      • 2012-08-31
      • 2014-02-19
      • 2011-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-26
      • 2015-04-02
      相关资源
      最近更新 更多