我已经通过类似问题进行了快速扫描,但大多数似乎没有真正回答我的问题。自定义帖子类型/分类网址结构
我有一个称为产品的自定义帖子类型。在那里,我有分类法,如房间类型,家具类型,材料等等。
该网站需要一个真正特定的网址结构来坚持它的SEO策略。
目前,我得到这样的:
/room-type/handles/bathroom
/room-type/handles/kitchen
/room-type/handles/modern
我需要删除房型,基本上是。我试图在注册分类时将“with_front”设置为false,但没有成功。
下面是我目前的代码,任何帮助极大的赞赏。
register_taxonomy(
'room-type',
'products',
array(
'label' => __('Room Type'),
'rewrite' => array(
'slug' => 'room-type',
'with_front' => true,
'hierarchical' => true,
),
'hierarchical' => true,
)
);
UPDATE
所以我做了一点挖掘,找到了这个网页:https://wordpress.stackexchange.com/questions/5413/need-help-with-add-rewrite-rule
...这是我最后的代码 - 这在目前看来是我已经拿出来的最接近的东西了:
function sb_rewrites() {
add_rewrite_rule('handles/([^/]+)/?', 'index.php?room-type=$matches[1]', 'top');
}
add_action('init', 'sb_rewrites', 10, 0);
function strip_room_type($link, $term, $taxonomy){
if ($taxonomy !== 'room-type')
return $link;
return str_replace('room-type/', '', $link);
}
add_filter('term_link', 'strip_room_type', 10, 3);
谢谢!
感谢您的配合!我试过使用第一个链接中概述的解决方案之一 - 不幸的是它似乎打破了我的网站。将不得不深入一点! –