WordPress的自定义帖子类型每年/每月档案
问题描述:
无论如何有每年或每月在WordPress的自定义帖子类型的档案? 我已经搜索了很多,无济于事。 我会想象的URL结构是这样的:WordPress的自定义帖子类型每年/每月档案
http://sitename/custom-post-type/year/month
有人吗?
答
您可以试试这段代码。将阵列中的CPT替换为您的CPT名称。
此功能将转换下列URL
到
这实际上是使用由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');
}
}
这个插件获取固定链接结构的工作:http://wordpress.org/extend/plugins/custom-post-permalinks/ 但仍不能产生一个列表中给出了正确的链接,每年的存档的自定义帖子类型。 – beetrootman 2010-09-26 18:28:35