如果您的问题是这样的:
A类-子类1-子类2-子类3
然后在主题中创建以下内容functions.php
:
//create the main category
wp_insert_term(
// the name of the category
\'Category A\',
// the taxonomy, which in this case if category (don\'t change)
\'category\',
array(
// what to use in the url for term archive
\'slug\' => \'category-a\',
));
然后针对每个子类别:
wp_insert_term(
// the name of the sub-category
\'Sub-category 1\',
// the taxonomy \'category\' (don\'t change)
\'category\',
array(
// what to use in the url for term archive
\'slug\' => \'sub-cat-1\',
// link with main category. In the case, become a child of the "Category A" parent
\'parent\'=> term_exists( \'Category A\', \'category\' )[\'term_id\']
));
希望这有帮助。