Php 使用WordPress短代码复制引导4个选项卡

Php 使用WordPress短代码复制引导4个选项卡,php,wordpress,tabs,bootstrap-4,shortcode,Php,Wordpress,Tabs,Bootstrap 4,Shortcode,正在尝试使用WordPress短代码创建引导选项卡 我构建的短代码的结构如下: [tabs tabcount="3"] [tab title="Tab A"] This is Tab A content [/tab] [tab title="Tab B"] This is Tab B content [/tab] [tab title="Tab C"] This is Tab C content [/tab] [/tabs] 用户在

正在尝试使用WordPress短代码创建引导选项卡

我构建的短代码的结构如下:

[tabs tabcount="3"]

   [tab title="Tab A"]
   This is Tab A content
   [/tab]

   [tab title="Tab B"]
   This is Tab B content
   [/tab]

   [tab title="Tab C"]
   This is Tab C content
   [/tab]

[/tabs]
用户在tabcount属性中输入他们正在创建的选项卡数量,然后函数应使用该属性输出x个选项卡数量和选项卡内容区域

function bootstrap_tabs_wrapper($atts, $content = null){

    $atts = shortcode_atts(
        array(
            'id' => '',
            'class' => '',
            'title' => '',
            'tabcount' => '',
        ), $atts
    );

    global $tabcount;
    $tabcount = $atts['tabcount'];

    $output  = '<section class="tabs" data-tabcount="'.$tabcount.'">';
    $output .= do_shortcode($content);
    $output .= '</section>';

    return $output;


}
add_shortcode('tabwrap', 'bootstrap_tabs_wrapper');


// actual tabs bit inside the main tab
function bootstrap_tabs_content($atts, $content = null) {

    $atts = shortcode_atts(
        array(
            'id' => '',
            'class' => '',
            'title' => '',
        ), $atts
    );


    // if currentTab is < number of tabs user has chosen in shortcode attribute
    for ($currentTab=0; $currentTab<$GLOBALS['tabcount'];$currentTab++){

        // check if first tab and add active class
        $active = '';
        if($currentTab === 0){
            echo '<nav class="nav nav-tabs" id="myTabs" role="tablist">';
            $active = 'active';
        }

        echo '<a class="nav-item nav-link '.$active.'" id="'.$currentTab.'-tab" data-toggle="tab" href="#'.$currentTab.'" role="tab" aria-controls="'.$currentTab.'" aria-selected="true">'.$atts['title'].'</a>';
    }

    echo '</nav>';


    // if currentTabContent < number of tabs user has chosen in shortcode attribute
    for ($currentTabContent=1; $currentTabContent<$GLOBALS['tabcount'];$currentTabContent++){

        // check if first tab content area and add active class
        $active = '';
        if($currentTabContent === 1){
            echo '<div class="tab-content" id="mytabContent">';
            $active = 'active';
        }

        echo '<div class="tab-pane fade show '.$active.'" id="'.$currentTabContent.'" role="tabpanel" aria-labelledby="'.$currentTabContent.'-tab">'.do_shortcode($content).'</div>';

    }       
    echo '</div>';
}
add_shortcode('mytabs', 'bootstrap_tabs_content');
function bootstrap\u tabs\u wrapper($atts,$content=null){
$atts=短码\附加(
排列(
“id'=>”,
“类”=>“”,
'标题'=>'',
“tabcount'=>”,
),$atts
);
全球$tabcount;
$tabcount=$atts['tabcount'];
$output='';
$output.=do_短代码($content);
$output.='';
返回$output;
}
添加快捷代码(“tabwrap”、“bootstrap”选项卡“wrapper”);
//主选项卡内的实际选项卡位
函数引导选项卡内容($atts,$content=null){
$atts=短码\附加(
排列(
“id'=>”,
“类”=>“”,
'标题'=>'',
),$atts
);
//如果currentTab小于用户在快捷码属性中选择的选项卡数

对于($currentTab=0;$currentTab,您有一个
tabwrap
mytabs
快捷码而不是
tabs
tab
,为什么需要
tabcount
?抱歉。以上内容应为[tabwrap]和[mytabs]对于shortcode。问题仍然是一样的。我每次都使用tabcount来计算和添加节,它应该在标记中显示每个选项卡-currentTab变量检查tabcount变量。或者我误解了这应该如何工作…?现在您正在使用循环来创建选项卡和选项卡标题,您重复t循环3次,这就是为什么你有3个标签头你有一个
tabwrap
mytabs
快捷码而不是
tabs
tab
,为什么你需要一个
tabcount
?道歉。上面应该读作[tabwrap]和[mytabs]对于shortcode。问题仍然是一样的。我每次都使用tabcount来计算和添加节,它应该在标记中显示每个选项卡-currentTab变量检查tabcount变量。或者我误解了这应该如何工作…?现在您正在使用循环来创建选项卡和选项卡标题,您重复t循环3次,这就是为什么有3个选项卡标题