0

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.

1 Answer 1

1

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');
4
  • 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). Commented Jan 31, 2012 at 18:22
  • Paste that in the functions.php? Commented Dec 23, 2012 at 20:48
  • @Helgi , yep in the functions.php would be fine. Commented Dec 23, 2012 at 21:01
  • Please igonre... spoke too soon Commented Apr 24, 2013 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.