2012-01-11 3 views
0

여러 쇼트 코드를 만들고 싶습니다. Wordpress Shortcode

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

어떻게 워드 프레스에 그렇게?

+1

처럼 사용하여 더 나은 아무것도를 읽지도 없다 [공식 문서] (http : //codex.wordpress. org/Shortcode_API) – balexandre

+0

[ID 속성은 고유해야 함을 깨닫습니다] (http://www.w3.org/TR/html4/struct/global.html#h-7.5.2) 또한 [WordPress]가 있습니다 (http://wordpress.stackexchange.com/) stack exchange site .. 문제에 대한 구체적인 도움을 찾고 있지 않지만 wordpress plugin을 개발하는 방법에 대한 지침을 찾고있을 때이 게시물을 게시해야합니다. – rlemon

답변

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 */ 
} 
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] 
관련 문제