2012-09-25 28 views
1
function getWidgets($position = null) { 
    if (empty($this->widgets)) { 
     foreach (wp_get_sidebars_widgets() as $pos => $ids) { 
      $this->widgets[$pos] = array(); 
      foreach ($ids as $id) {     // error is here 
       $this->widgets[$pos][$id] = $this->getWidget($id); 
      } 
     } 
    } 
} 

這些是305-314行。使用wordpress時的foreach()錯誤wp_get_sidebars_widgets()

我得到這個錯誤:

" Warning: Invalid argument supplied for foreach() in /home/content/73/9889573/html/wp-content/themes/yoo_spark_wp/warp/systems/wordpress.3.0/helpers/system.php on line 310 " 

誰能告訴我怎麼解決呢

+0

你的行號是有點偏離,因爲線310是'$這 - >小窗口[$ POS] [$ ID] = $這 - > getWidget($ ID); '但錯誤指的是foreach循環中的參數。 –

+0

我的回答對你有幫助嗎? –

回答

2

wp_get_sidebars_widgets()返回一維數組。

參考http://codex.wordpress.org/Function_Reference/wp_get_sidebars_widgets

$ids不是數組。你不能在foreach循環中遍歷它。

嘗試這種情況:

$widgets = array(); 
foreach (wp_get_sidebars_widgets() as $pos => $id) { 
    $widgets[$pos] = $this->getWidget($id); 
} 
+0

那麼我該怎麼做..即時通訊失去了.php –

+0

答覆更新。 –

+0

做到了這一點,並得到這個「警告:isset中的非法偏移類型或/home/content/73/9889573/html/wp-content/themes/yoo_spark_wp/warp/systems/wordpress.3.0/helpers/system.php中的空255行「 –