我收到此数组错误
"Fatal error: Cannot use object of type stdClass as array"
在Wordpress文件category.php上。当我没有类别的任何子类别时,问题就会到来,所以如果子类别列表为0,我会尝试处理。
但我一直得到同样的错误,有人能看到我在这里做的错误吗?
错误出现在以下行中:
"if ($category[0]->category_parent == 0) {"
括号内的整个代码。
<?php
$args = array(
'type' => 'post',
'child_of' => $cat_id,
'parent' => get_query_var(''),
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => 0,
'hierarchical' => 1,
'exclude' => '',
'include' => '',
'number' => '',
'taxonomy' => 'category',
'pad_counts' => true );
$categories = get_categories($args);
if ($category[0]->category_parent == 0) {
$tag = $category[0]->cat_ID;
$tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
if (isset($tag_extra_fields[$tag])) {
$category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
$category_icon_color = $tag_extra_fields[$tag]['category_icon_color'];
}
} else {
$tag = $category[0]->category_parent;
$tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
if (isset($tag_extra_fields[$tag])) {
$category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
$category_icon_color = $tag_extra_fields[$tag]['category_icon_color'];
}
}
foreach($categories as $category) { ?>