我收到以下通知未定义的偏移量: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>
错误在这行
if($category[0]){
如何修复通知
isset检查变量是否为undefined或NULL并返回false
if(isset($category) && isset($category[0])) {
...
}
或更快的相同逻辑:
if(isset($category, $category[0])) {
}