Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Pastebin of the html prototype and my attempt at the wp function -> http://pastebin.com/91zBv8sk

I want a simple notation so its easy for new users to use. So something like this:

[tabs]

[tab title="tab title"]Content of the first tab[/tab]

[tab title="second tab title"]Content of the second tab[/tab]

[/tabs]

I understand why the function's notation is wrong but I figured I'd leave my best attempt.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Try This:

function defaulttab( $atts, $content = null ) {
    $GLOBALS['tab_count'] = 0;
    do_shortcode($content)
    if( is_array( $GLOBALS['tabs'] ) ){
        $i = 1;
        foreach( $GLOBALS['tabs'] as $tab ){
            $tabs[] = '<li><a class="tab" href="#">'.$tab['title'].'</a></li>';
            $panes[] = '<div class="tab'.$i.'" class="tabcontent">' .$tab['content'].'</div>';
            $i++;
        }
        $return = '<div class="tabcontainer"><ul class="selector">'.implode( "\n", $tabs ).'</ul>
            <div class="clear"></div>'.implode( "\n", $panes ).'</div>';
    }
    return $return;
}


add_shortcode('tab', 'defaulttab');

function defaulttabs( $atts, $content = null ) {
    extract( shortcode_atts( array(
    'title' => '',
    'tab' => '1',
    ), $atts ) );

    $i = $GLOBALS['tab_count'];
    $GLOBALS['tabs'][$i] = array( 'title' => sprintf( $title, $GLOBALS['tab_count'] ), 'content' =>  $content );
    $GLOBALS['tab_count']++;
}

add_shortcode('tabs', 'defaulttabs');
share|improve this answer
1  
Thanks, it works (or rather will work with some slight modifications). I'm curious to understand how the function works, though (if you wouldn't mind explaining in brief detail). –  pope Jan 31 '12 at 18:22
    
Paste that in the functions.php? –  user25172 Dec 23 '12 at 20:48
    
@Helgi , yep in the functions.php would be fine. –  Bainternet Dec 23 '12 at 21:01
    
Please igonre... spoke too soon –  Sagive SEO Apr 24 '13 at 14:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.