0

我想创建一个类似这样的多个短代码。

[tabs]

[tab title="1"]
//content goes here
[/tab]

[tab title="2"]
//content2 goes here
[/tab]

[tab title="3"]
//content4 goes here
[/tab]

[/tabs]

预期输出:

<ul>
    <li id="tab1">[tab title="1" goes here]</li>
    <li id="tab2">[tab title="2" goes here]</li>
    <li id="tab3">[tab title="3" goes here]</li>
</ul>

<ul id="tab1">
    <li>Content1</li>
</ul>

<ul id="tab2">
    <li>Content2</li>
</ul>

<ul id="tab3">
    <li>Content3</li>
</ul>

如何在 WordPress 中做到这一点?

4

2 回答 2

0
add_shortcode('external', 'externalFunction');
function externalFunction( $atts,$content = null){
     echo do_shortcode('[internal]'.$content.'[/internal]');
}

add_shortcode('internal','internalFunction');
function internalFunction($atts, $content=null)
{
  extract(shortcode_atts(
      array(
            "title" => ''
        ), $atts));  
      /* do your stuffs here */
}
于 2012-01-11T08:27:07.843 回答
0

首先创建“标签”短代码

function tabs_shortcode( $atts, $content ) {
    $atts = shortcode_atts( array(      
            'id' => ''        
            ), $atts );

extract ($atts); // gives you the ability to use array keys as variables

    return '<ul id="'. $id.'">'. do_shortcode( $content ) .'</ul>';

}
add_shortcode( 'tabs', 'tabs_shortcode' );

现在创建“标签”短代码

function tab_shortcode( $atts, $content ) {
   $atts = shortcode_atts( array(       
           'id' => ''        
           ), $atts );

extract ($atts); // gives you the ability to use array keys as variables

    return '<li id="'. $id.'">'. do_shortcode( $content ) .'</li>';

}
add_shortcode( 'tab', 'tab_shortcode' );

像这样使用它

[tabs id="tab"]
   [tab id="tab1"] lorem ipsum dolor [/tab]
   [tab id="tab2"] lorem ipsum dolor [/tab]
   [tab id="tab3"] lorem ipsum dolor [/tab]
[/tab]
于 2016-02-04T05:44:05.020 回答