【发布时间】:2016-12-04 16:16:39
【问题描述】:
此代码在 wordpress 管理区域中正确显示类别。但不显示子类别。
我需要为每个类别显示 3 个类别和 3 个子类别?
这是我希望每个类别都有的:
A 类
- 子类 1
- 子类 2
- 子类别 3
我在 wordpress 主题的 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']
));
但我收到一个错误:
解析错误:解析错误,在第 57 行期待 `')'' ...
对应'parent'=> term_exists( 'Category A', 'category' )['term_id']。
我做错了什么?
【问题讨论】:
-
在子类别函数中出现解析错误。
标签: php wordpress categories