为foreach提供的Wordpress参数无效
您好,这是我的网站,我在标题上收到此错误 错误代码: 警告 :为中的foreach()提供的参数无效 /home/enghouse/kastratihome.com/wp-content/themes/funiter/framework/includes/theme-functions.php 在线 828 我的代码:为foreach提供的Wordpress参数无效,wordpress,Wordpress,您好,这是我的网站,我在标题上收到此错误 错误代码: 警告 :为中的foreach()提供的参数无效 /home/enghouse/kastratihome.com/wp-content/themes/funiter/framework/includes/theme-functions.php 在线 828 我的代码: 823 if ( $funiter_enable_vertical == 1 ) : 824 $locations = get_nav_menu_locations
823 if ( $funiter_enable_vertical == 1 ) :
824 $locations = get_nav_menu_locations();
825 $menu_id = $locations['vertical_menu'];
826 $menu_items = wp_get_nav_menu_items( $menu_id );
827 $count = 0;
828 foreach ( $menu_items as $menu_item ) {
829 if ( $menu_item->menu_item_parent == 0 ) {
830 $count ++;
831 }
832 }
这是代码,请帮我 您应该确保使用is\u array函数将数组传递给foreach
try{
/* [ your iteration on header.php, line 828, likely something that looks like foreach($foo as $f) { ... } */
}
catch(Exception $e){
/* technically, you don't need to do anything here unless it serves you */
/* but it's common to log an error or return a value */
}
如果不确定是否要传递数组,则可以按如下方式更改代码。
如果您不确定它是否将是一个数组,则始终可以使用以下PHP示例代码进行检查:
if(is_array($value) || is_object($value)){
foreach ($variable as $item) {
//do something
}
}
在/home/enghouse/kastratihome.com/wp-content/themes/funiter/framework/includes/theme-functions.php中检查您的foreach(),并确保在使用foreach()之前检查它是否是一个数组。您能定义多一点吗,我必须在function.php或??