我希望创建一个永久链接URL结构,大致如下:帖子类型名称:汽车分类名称:经销商术语名称:本田帖子标题:123 Hot Rod Lane理想permalink URL结构的示例设置:
Generic permalink structure:
domain.com/post-type-name/taxonomy-name/term-name/post-title/
More specific permalink structure: domain.com/cars/dealers/honda/123-hot-rod-lane/
/cars/
需要作为post类型中每个postmade的存档列表进行访问/cars/dealers/
需要作为分类法中每个帖子的归档列表进行访问/cars/dealers/honda/
需要作为该分类术语中的每篇文章的存档列表进行访问/cars/dealers/honda/123-hot-rod-lane/
需要可以访问汽车定制立柱类型中立柱的矩形视图
我只是想说清楚,所以在回答这个问题时,没有人做任何不必要的工作。除了为我的帖子类型、分类法和术语添加正确的重写规则之外,我不需要其他任何东西。这个问题直接涉及permalink URL rewriting, 与职位或档案清单无关。我只需要确保WordPress正确识别它们,同时使用条件调用,如is_post_type_archive()
或is_tax()
或is_singular()
, 等我已经尝试过无数次,从这个网站上的无数问题/答案中。似乎什么都没用。
这是我注册的自定义帖子类型和注册的自定义分类:
public function register_custom_data(){
/* Register a post type for Cars. */
$labels = array(
\'name\' => _x(\'Cars\', \'post type general name\'),
\'singular_name\' => _x(\'Car\', \'post type singular name\'),
\'add_new\' => _x(\'Add New Car\', \'Car\'),
\'add_new_item\' => __(\'Add New Car\'),
\'edit_item\' => __(\'Edit Car\'),
\'new_item\' => __(\'New Car\'),
\'all_items\' => __(\'All Cars\'),
\'view_item\' => __(\'View Car\'),
\'search_items\' => __(\'Search Cars\'),
\'not_found\' => __(\'No Cars found\'),
\'not_found_in_trash\' => __(\'No Cars found in Trash\'),
\'parent_item_colon\' => \'\',
\'menu_name\' => __(\'Cars\')
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'show_in_menu\' => false,
\'show_in_nav_menus\' => false,
\'can_export\' => true,
\'query_var\' => true,
\'rewrite\' => true,
\'menu_icon\' => NULL,
\'capability_type\' => \'post\',
\'has_archive\' => true,
\'hierarchical\' => false,
\'menu_position\' => NULL,
\'supports\' => array(
\'title\',
\'editor\',
\'thumbnail\'
),
\'rewrite\' => array(
\'slug\' => \'cars\',
\'with_front\' => true
)
);
register_post_type(\'mbe_cars\', $args);
/* Car Dealers */
$labels = array(
\'name\' => _x(\'Dealers\', \'taxonomy general name\'),
\'singular_name\' => _x(\'Dealer\', \'taxonomy singular name\'),
\'search_items\' => __(\'Search Dealers\'),
\'all_items\' => __(\'All Dealers\'),
\'parent_item\' => __(\'Parent Dealer\'),
\'parent_item_colon\' => __(\'Parent Dealer:\'),
\'edit_item\' => __(\'Edit Dealer\'),
\'update_item\' => __(\'Update Dealer\'),
\'add_new_item\' => __(\'Add New Dealer\'),
\'new_item_name\' => __(\'New Dealer Name\'),
\'menu_name\' => __(\'Dealers\')
);
$args = array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'dealers\',
\'hierarchical\' => true
)
);
register_taxonomy(\'mbe_car_dealers\', \'mbe_cars\', $args);
/* Update urls. */
flush_rewrite_rules();
}