wordpress tags标签改造id显示加后缀html显示
代码语言:javascript
复制
/* 标签以id+html方式展示*/
add_action('generate_rewrite_rules','tag_rewrite_rules');
add_filter('term_link','tag_term_link',10,3);
add_action('query_vars', 'tag_query_vars');
function tag_rewrite_rules($wp_rewrite){
$new_rules = array(
'tag/(\d+)/feed/(feed|rdf|rss|rss2|atom).html' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
'tag/(\d+)/(feed|rdf|rss|rss2|atom).html' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
'tag/(\d+)/embed.html' => 'index.php?tag_id=$matches[1]&embed=true',
'tag/(\d+)/page/(\d+).html' => 'index.php?tag_id=$matches[1]&paged=$matches[2]',
'tag/(\d+).html' => 'index.php?tag_id=$matches[1]',
);
$wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
}
function tag_term_link($link,$term,$taxonomy){
if($taxonomy=='post_tag'){
return home_url('/tag/'.$term->term_id.'.html');
}
return $link;
}
function tag_query_vars($public_query_vars){
$public_query_vars[] = 'tag_id';
return $public_query_vars;
}
效果:
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。