我通过阅读了解到这一点this article. 这很简单,我所要做的就是:
更改$talks_cat_args[rewrite][slug]
从…起\'talks\'
到\'talks/category\'
(我以前试过)但没成功…
确保register_taxonomy
在之前register_post_type
.读了这篇文章,但这基本上是因为“WP\\U重写的工作原理是,从某种程度上讲,破译永久链接的过程是自上而下的”
为了子孙后代,这里是最后的代码(稍加修改)。我不能说这是最好或最干净的方法,因为我对WordPress&;很陌生;PHP,但到目前为止它仍在工作。
$talks_labels = array(
\'name\' => \'Talks\',
\'singular_name\' => \'Talk\',
\'all_items\' => \'All Talks\',
\'add_new\' => \'Add new\',
\'add_new_item\' => \'Add new Talk\',
\'edit_item\' => \'Edit Talk\',
\'new_item\' => \'New Talk\',
\'view_item\' => \'View Talk\',
\'search_items\' => \'Search Talks\',
\'not_found\' => \'No Talks found\',
\'not_found_in_trash\' => \'No Talks found in Trash\',
);
$talks_args = array(
\'labels\' => $talks_labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'menu_position\' => 5,
\'rewrite\' => array( \'slug\' => \'talks\', \'with_front\' => false ),
\'has_archive\' => \'talks\',
);
$talks_cat_labels= array(
\'name\' => \'Talk categories\',
\'singular_name\' => \'Talk category\',
\'search_items\' => \'Search talk categories\',
\'all_items\' => \'All talk categories\',
\'parent_item\' => \'Parent talk category\',
\'parent_item_colon\' => \'Parent talk category:\',
\'edit_item\' => \'Edit talk category\',
\'update_item\' => \'Update talk category\',
\'add_new_item\' => \'Add new talk category\',
\'new_item_name\' => \'New talk category name\',
);
$talks_cat_args = array(
\'hierarchical\' => true,
\'labels\' => $talks_cat_labels,
\'show_admin_column\' => true,
\'show_ui\' => true,
\'query_var\' => true,
\'rewrite\' => array(
\'slug\' => \'talks/category\',
\'with_front\' => false
),
);
register_taxonomy( \'uc_talks_cat\', array(\'uc_talks\'), $talks_cat_args );
register_post_type( \'uc_talks\', $talks_args );