WordPress 简码

发布于 2024-12-26 05:42:55 字数 678 浏览 2 评论 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 中做到这一点?

I want to create a multiple shortcodes something likes this.

[tabs]

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

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

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

[/tabs]

expected output :

<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>

How to do that in WordPress?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

悲凉≈ 2025-01-02 05:42:55

首先创建“tabs”简码

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' );

现在创建“tab”简码

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]

First create "tabs" shortcode

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' );

Now create "tab" 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' );

Use it like this

[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]
快乐很简单 2025-01-02 05:42:55
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 */
}
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 */
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文