【问题标题】:Wordpress custom post type yearly/monthly archivesWordPress 自定义帖子类型每年/每月档案
【发布时间】:2011-04-17 10:16:31
【问题描述】:
【问题讨论】:
标签:
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');
}
}