2010-09-26 76 views
0

无论如何有每年或每月在WordPress的自定义帖子类型的档案? 我已经搜索了很多,无济于事。 我会想象的URL结构是这样的:WordPress的自定义帖子类型每年/每月档案

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

有人吗?

+0

这个插件获取固定链接结构的工作:http://wordpress.org/extend/plugins/custom-post-permalinks/ 但仍不能产生一个列表中给出了正确的链接,每年的存档的自定义帖子类型。 – beetrootman 2010-09-26 18:28:35

回答

0

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

0

您可以试试这段代码。将阵列中的CPT替换为您的CPT名称。

此功能将转换下列URL

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

这实际上是使用由WordPress

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

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'); 
    } 


} 
相关问题