douyun6781 2013-10-06 03:41
浏览 33
已采纳

未识别的索引错误

I am using a plugin for WordPRess called Easy Bootstrap Shortcodes to use Booystrap CSS within wordpress posts. Tabs are one feature I use a lot and when I use the tabs short code, it throws the following error:

Notice: Undefined index: tabs in /home/onedirec/public_html/tester/wp-content/plugins/easy-bootstrap-shortcodes/shortcode/tabs/plugin_shortcode.php on line 38

What's weird is that the tabs and all the information following is rendered apart from an indent that shouldn;t be there. You can see this in action here: http://onedirectionconnection.com/tester/?projects=take-me-home-tour

If anyone could help me figure out what the issue is, it would be greatly appreciated. Here's the code that's causing the error:

<?php

/* * *********************************************************
 * jQuery UI Tabs
 * ********************************************************* */
$_oscitas_tabs = array();

function osc_theme_tabs($params, $content = null) {
    global $_oscitas_tabs;
    extract(shortcode_atts(array(
                'id' => count($_oscitas_tabs),
                'class' => ''
                    ), $params));
    $_oscitas_tabs[$id] = array();
    do_shortcode($content);
    $scontent = '<ul class="nav nav-tabs " id="oscitas-tabs-' . $id . '">' . implode('', $_oscitas_tabs[$id]['tabs']) . '</ul><div
    class="tab-content">' . implode('', $_oscitas_tabs[$id]['panes']) . '</div>';
    if (trim($scontent) != "") {
        $output = '<div class="' . $class . '">' . $scontent;
        $output .= '</div>';

        return $output;
    } else {
        return "";
    }
}

add_shortcode('tabs', 'osc_theme_tabs');

function osc_theme_tab($params, $content = null) {
    global $_oscitas_tabs;
    extract(shortcode_atts(array(
                'title' => 'title',
                'active' => '',
                    ), $params));

    $index = count($_oscitas_tabs) - 1;
    $pane_id = 'pane-' . $index . '-' . count($_oscitas_tabs[$index]['tabs']);
    $_oscitas_tabs[$index]['tabs'][] = '<li class="' . $active . '"><a href="#' . $pane_id . '" data-toggle="tab">' . $title
            . '</a></li>';
    $_oscitas_tabs[$index]['panes'][] = '<div class="tab-pane ' . $active . '" id="'
            . $pane_id . '">'
            . do_shortcode
                    (trim($content)) . '</div>';
}

add_shortcode('tab', 'osc_theme_tab');

And here is line 38 on its own:

$pane_id = 'pane-' . $index . '-' . count($_oscitas_tabs[$index]['tabs']);

I know very little about PHP so if anyone can help me spot the error here, it would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • dsqve08622 2013-10-06 05:23
    关注

    Well I'll just post the answer here since it worked in the comments.

    Add this line just before line 38:

    $_oscitas_tabs[$index]['tabs'] = array(); 
    

    Right above this line:

    $pane_id = 'pane-' . $index . '-' . count($_oscitas_tabs[$index]['tabs']);
    

    That should stop the PHP notice from appearing.

    You could try adding a @ right before count()

    $pane_id = 'pane-' . $index . '-' . @count($_oscitas_tabs[$index]['tabs']);
    

    It keeps PHP from complaining.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法