请协助我解决 Undefined offset: 0 in /public_html/wp-content/themes/modus-child/functions.php on line 51

Please assist me in resolving an Undefined offset: 0 in /public_html/wp-content/themes/modus-child/functions.php on line 51

在与原始网站开发人员的沟通中断后,我继承了一个有问题的网站。

我一直在努力解决并解决尽可能多的错误。

PHP Notice: Undefined offset: 0 in /home/customer/www/public_html/wp-content/themes/modus-child/functions.php on line 51

长期目标是重新构建网站,使用不同的主题,但我希望能为解决此错误提供一些帮助,以便在开发过程中为我们提供安全网。

Screenshot showing the code as pasting the code didn't look right

这里是第46行以后 第 51 行是以 if($featured[0]=="Featured"){ 开头的行 我可以在括号中看到偏移量 0。

$count=0;
      foreach ($woo_catgery as $sc) {
            $count++;
            if($count==6){continue;}
            $featured = get_field('featured', $sc->taxonomy . '_' . $sc->term_id);
            if($featured[0]=="Featured"){
            $thumbnail_id = get_term_meta( $sc->term_id, 'thumbnail_id', true );
            $image_url=wp_get_attachment_url( $thumbnail_id ); 
            if(!empty($image_url)){
                $image_url=$image_url;
            }else{$image_url=get_stylesheet_directory_uri().'/img/blank.png';}
            $link = get_term_link( $sc->slug, $sc->taxonomy );
            $hm .='<li>
                    <div class="cat_image">
                        <a href="'. $link .'" title="" target="_self">        
                            <img alt="icon" src="'.$image_url.'">
                        </a>                    
                    </div>
                    <div class="cat_bx_cnt">
                        <div class="cat_ttl">
                            <h3 class="cat_ttl_mn">'.$sc->name.'</h3>                      
                        </div>
                        <a class="link-more" href="'. $link .'" title="" target="_self">
                            <i class="fa fa-angle-right" aria-hidden="true"> </i>
                        </a>
                    </div>
                </li>               
            '; 
            }
      }
      $hm .='</ul>';
      return $hm;
    
}
add_filter( 'woocommerce_marketing_menu_items', '__return_empty_array' );

add_action( 'after_setup_theme', 'remove_pgz_theme_support', 100 );

function remove_pgz_theme_support() { 
remove_theme_support( 'wc-product-gallery-zoom' );
}

$featured 似乎是一个空数组,因此您应该首先检查它是否包含元素:

if(count($featured) > 0 && $featured[0]=="Featured")