需要帮助未定义的偏移错误

时间:2012-07-23 14:42:40

标签: php wordpress

想知道是否有人可以帮助我。我一直在寻找答案的地方,似乎找不到答案。

我是PHP的新手,我对WordPress非常熟悉。我在默认的Twentyeleven主题中添加了三个新布局。我设想这种工作的方式是,如果某人选择了特定的布局,则会出现额外的侧边栏。所以我想出了以下内容(是的,我知道它可能不正确,但我自己做了,它有效......哈哈)

            $options = themeawesome_get_theme_options();
            $classes = $options['three-column' || 'three-column-left' || 'three-column-right'];
            if ( 'content' != $classes ) {
            get_sidebar('alt');
            }

就像说它效果很好并且如果在主题选项面板中选择了任何选项,则会显示alt侧边栏。

唯一的问题是我收到以下错误:

  

未定义的偏移量:第8行的1

第8行是上面的第2行代码。

任何人都可以帮我删除此错误。非常感谢任何帮助,并提前感谢您。

1 个答案:

答案 0 :(得分:0)

您不能在数组中使用多个索引,因为您尝试执行以下操作:

$classes = $options['three-column' || 'three-column-left' || 'three-column-right'];

我不确定你要达到的目标是什么,所以我有多个答案可以解决它。

首先,声明可用主题列表:

$themes = array('three-column', 'three-column-left', 'three-column-right');

如果您想要每个类的数组$classes,请尝试:

$classes = array();
foreach ($themes as $theme) {
    if (isset($options[$theme])) {
        $classes = $options[$theme]; 
    }
}

如果您想获得“第一个主题”,请尝试:

$classes = '';
foreach ($themes as $theme) {
    if (isset($options[$theme])) {
        $classes = $options[$theme];
        break;
    }
}

因为您正在关注if语句(if ('content' != $classes))正在检查单个字符串,所以我的第二个示例可能符合您的需求。

相关问题