Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function tab_shortcode($atts) {
- extract(shortcode_atts(array(
- 'category' => '',
- ), $atts, 'tablist'));
- $q = new WP_Query(
- array('posts_per_page' => '10', 'post_type' => 'tab-items', 'tab_category' => $category)
- );
- $list = '
- <script type="text/javascript">
- jQuery(function() {
- jQuery("ul.tabnav li:first-child").addClass("active")
- jQuery("div.tab-pane").first().addClass("active")
- });
- </script>
- <div role="tabpanel">
- <ul class="tabnav nav nav-tabs" role="tablist">
- ';
- while ($q->have_posts()) : $q->the_post();
- $tab_id = get_the_ID();
- $list .= '
- <li role="presentation"><a href="#'.$tab_id.'" aria-controls="' . get_the_title() . '" role="tab" data-toggle="tab">' . get_the_title() . '</a></li>
- ';
- endwhile;
- $list.= '
- </ul>
- <div class="tab-content">
- ';
- while ($q->have_posts()) : $q->the_post();
- $tab_id = get_the_ID();
- $list .= '
- <div role="tabpanel" class="tab-pane" id="'.$tab_id.'">
- ' . get_the_content() . '</div>';
- endwhile;
- $list.= '
- </div>
- </div>
- ';
- wp_reset_query();
- return $list;
- }
- add_shortcode('tab', 'tab_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement