Advertisement
xpeed

tab post type

Feb 7th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. function tab_shortcode($atts) {
  2. extract(shortcode_atts(array(
  3. 'category' => '',
  4.  ), $atts, 'tablist'));
  5.  
  6. $q = new WP_Query(
  7. array('posts_per_page' => '10', 'post_type' => 'tab-items', 'tab_category' => $category)
  8. );
  9.  
  10. $list = '
  11.        <script type="text/javascript">
  12.        jQuery(function() {
  13.        jQuery("ul.tabnav li:first-child").addClass("active")
  14.        jQuery("div.tab-pane").first().addClass("active")
  15.        });
  16.        </script>
  17.        <div role="tabpanel">
  18.        
  19.                <ul class="tabnav nav nav-tabs" role="tablist">
  20.        ';
  21.  
  22.         while ($q->have_posts()) : $q->the_post();
  23.         $tab_id = get_the_ID();
  24.         $list .= '
  25.                <li role="presentation"><a href="#'.$tab_id.'" aria-controls="' . get_the_title() . '" role="tab" data-toggle="tab">' . get_the_title() . '</a></li>        
  26.                ';
  27.         endwhile;
  28.         $list.= '
  29.                 </ul>
  30.           <div class="tab-content">
  31.        ';
  32.  
  33.  
  34.         while ($q->have_posts()) : $q->the_post();
  35.         $tab_id = get_the_ID();
  36.         $list .= '
  37.                <div role="tabpanel" class="tab-pane" id="'.$tab_id.'">
  38.                        ' . get_the_content() . '</div>';
  39.         endwhile;
  40.         $list.= '
  41.                </div>
  42.            </div>
  43.        ';
  44. wp_reset_query();
  45. return $list;
  46. }
  47.  
  48. add_shortcode('tab', 'tab_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement