Php警告:在第30行为/home/padtvro/public_html/wp-content/themes/claudia/content.php中的Foreach()提供的参数无效

时间:2020-03-31 作者:Pop Daniel

在cpanel错误日志中,WordPress生成此错误:

PHP警告:在/home/padtvro/public\\u html/wp-content/themes/claudia/content中为foreach()提供的参数无效。php在线30

如果我删除它,它会在6-7小时后再次出现。有什么问题吗?

<section id="contents" class="clearfix"><div class="row main_content"><div class="container content_wraper"><?php the_breadcrumb(); ?><div class="grid_8" id="content"><div class="widget_container content_page"><?php require_once dirname(__FILE__) . \'/include/cat.php\'; ?> 
</div></div><div class="grid_4 p7ehc-a" id="sidebar">
<?php $ge_sidebar = \'\';
                 if (is_search()) {
                      $ge_sidebar = of_get_option(\'se_sidebar\',\'\');
                    }else if(is_category() ) {

                        $category = get_the_category();                     

                        $cn_sidebar =\'\';
                        foreach($category as $ca_id) {
                            if(empty($cn_sidebar)) { $cn_sidebar = of_get_option(\'cat_\'.$ca_id->term_id);}                              

                        }

                        if(empty($cn_sidebar)) {
                            $ge_sidebar = of_get_option(\'cat_sidebar\',\'\');
                        } else { $ge_sidebar = $cn_sidebar; }


                    } else if(is_author() ) {

                        $ge_sidebar = of_get_option(\'au_sidebar\',\'\');

                    }else if(is_tag() ) {

                        $tags = get_the_tags();                     

                        $cn_sidebar =\'\';
                        foreach($tags as $tg_id) {
                            if(empty($cn_sidebar)) { $cn_sidebar = of_get_option(\'tag_\'.$tg_id->term_id);}                              
                        }

                        if(empty($cn_sidebar)) {
                            $ge_sidebar = of_get_option(\'tag_sidebar\',\'\');
                        } else { $ge_sidebar = $cn_sidebar; }
                    }               



                $dyn_sidebar =\'\';
                if(!empty($ge_sidebar)) {   $dyn_sidebar = $ge_sidebar; };              

                foreach ( $GLOBALS[\'wp_registered_sidebars\'] as $sidebar ) {
                    if($sidebar[\'name\'] == $dyn_sidebar)
                        {
                             $dyn_sidebar = $sidebar[\'id\'];
                        }
                } 

                if(!empty($dyn_sidebar)) {
                    if (is_active_sidebar($dyn_sidebar)) : dynamic_sidebar($dyn_sidebar);
                    endif;  
                } else{
                    if (is_active_sidebar(\'center-sidebar\')) : dynamic_sidebar(\'center-sidebar\');
                    endif;
                }

    ?></div><div class="clear"></div></div></div></section>

1 个回复
SO网友:cjbj

错误由以下代码生成:

line 27 $tags = get_the_tags();                     
line 28
line 29                    $cn_sidebar =\'\';
line 30                    foreach($tags as $tg_id) {
如果帖子没有标签,get_the_tags() wil返回false。然后供应falseforeach 语句将为您提供所提到的错误。为了防止出现这种情况,应将foreach 在里面if (!empty($tags)) { foreach ...}.