Undefined variable Output
我从wordpress主题中以调试模式收到以下错误。 可能很容易解决,但我不知道该怎么办。
UNDEFINED VARIABLE: OUTPUT .... line 34 ($output variable)
1 2 3 4 5 6 7 | $categories = get_the_category(); if($categories) { foreach($categories as $category) { $output .= 'term_id ).'" class="btn-standard-blog" title="' . esc_attr( sprintf( __("View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.''; } } echo $output; |
您可以通过以下方法解决此问题:声明该变量不带任何值,然后在适当时进行修改。
1 2 3 4 5 6 7 8 9 | <?php $output = ''; $categories = get_the_category(); if($categories) { foreach($categories as $category) { $output .= 'term_id ).'" class="btn-standard-blog" title="' . esc_attr( sprintf( __("View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.''; } } echo $output; ?> |