wpexplorer

tabs

Nov 1st, 2011
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. add_shortcode( 'tabgroup', 'tab_group' );
  2. function tab_group( $atts, $content ){
  3. extract(shortcode_atts(array(
  4.     'set' => ''
  5. ), $atts));
  6.    
  7. $GLOBALS['tab_count'] = 0;
  8.  
  9. do_shortcode( $content );
  10.  
  11. if( is_array( $GLOBALS['tabs'] ) ){
  12.     $tab_count=0;
  13.     foreach( $GLOBALS['tabs'] as $tab ){
  14.     $tab_count++;
  15. $tabs[] = '<li><a href="#tabs-'. $set .'-'. $tab_count .'">'.$tab['title'].'</a></li>';
  16. $panes[] = '<div id="tabs-'. $set .'-'. $tab_count .'" class="tab_content">'. do_shortcode($tab['content']) .'</div>';
  17. }
  18. $return = "\n".'<div class="tabs"><ul class="clearfix">'.implode( "\n", $tabs ).'</ul>'."\n".''.implode( "\n", $panes ).'</div>'."\n";
  19. }
  20. return $return;
  21. }
  22.  
  23. add_shortcode( 'tab', 'single_tab' );
  24. function single_tab( $atts, $content ){
  25.    
  26. extract(shortcode_atts(array(
  27.     'title' => 'Tab %d'
  28. ), $atts));
  29.  
  30. $x = $GLOBALS['tab_count'];
  31. $GLOBALS['tabs'][$x] = array(
  32.                         'title' => sprintf( $title, $GLOBALS['tab_count'] ),
  33.                         'content' =>  $content
  34.                         );
  35.  
  36. $GLOBALS['tab_count']++;
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment