Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress错误通知:未定义的偏移量:0_Php_Wordpress - Fatal编程技术网

Php Wordpress错误通知:未定义的偏移量:0

Php Wordpress错误通知:未定义的偏移量:0,php,wordpress,Php,Wordpress,我收到以下通知 未定义的偏移量:0英寸 Category: <?php $category = get_the_category(); if($category[0]){ echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>'; }

我收到以下通知 未定义的偏移量:0英寸

Category: <?php $category = get_the_category(); 
                    if($category[0]){ 
                    echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>'; } 
                ?>
    | <?php comments_popup_link( 'Add a comment', '1 comment', '% Comments' ); ?>
</div>

如何修复通知。

设置检查变量是否未定义或为NULL,并返回false

或者更快、相同的逻辑:

if(isset($category, $category[0])) {

}

这不是一个错误,而是一个警告,它意味着没有$category[0],这意味着您的$category很可能是空的或不包含数组..可能重复检查您的数组您的数组是空的。您必须从仪表板添加类别。
if(isset($category) && isset($category[0])) {
    ...
}
if(isset($category, $category[0])) {

}