【问题标题】:foreach() error when using wordpress wp_get_sidebars_widgets()使用 wordpress wp_get_sidebars_widgets() 时出现 foreach() 错误
【发布时间】:2012-09-25 21:15:27
【问题描述】:
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 " 

谁能告诉我如何解决它

【问题讨论】:

  • 您的行号有点偏离,因为第 310 行是 $this->widgets[$pos][$id] = $this->getWidget($id);,但错误是指 foreach 循环中的参数。

标签: php wordpress foreach


【解决方案1】:

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);
}

【讨论】:

  • 那么我该放什么.. .php 时我迷路了
  • 这样做并得到了这个“警告:在 isset 中存在非法偏移类型或在 /home/content/73/9889573/html/wp-content/themes/yoo_spark_wp/warp/systems/wordpress.3.0 中为空/helpers/system.php 第 255 行“
猜你喜欢
  • 1970-01-01
  • 2019-07-19
  • 2018-08-05
  • 2017-09-04
  • 2014-11-18
  • 2012-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多