如何创建一个完整的永久链接结构:
/category-name/post-name/
而不是:
/category-slug/post-name/
默认情况下,Wordpress提供%category%
标记结构为"A sanitized version of the category name (category slug field on New/Edit Category panel"。
如何在永久链接中使用类别名称而不是类别slug?
答案 0 :(得分:0)
add_filter('rewrite_rules_array', 'category_name_rewrite_rule');
function category_name_rewrite_rule($rules) {
$new_rules = array();
$categories = get_categories();
foreach ($categories as $category) {
$cat_name = preg_replace('#\s+#', '-', $category->name);
$new_rules['/'.$category->slug}.'/'] = '/'.url_encode($cat_name).'/';
}
return $new_rules + $rules;
}
答案 1 :(得分:0)
我在这里找到了解决方案 - 使用 Custom_post_types 代替类别 ... https://wordpress.stackexchange.com/questions/28979/how-to-change-permalink-structure-for-custom-post-type-and-its-taxonomies/#167992