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 行。

我收到此错误:

" 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 " 

有人可以告诉我如何解决它

4

1 回答 1

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);
}
于 2012-09-25T21:20:13.363 回答