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.

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

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码