Advertisement
azad_rpi

Dynamic Tab Using shortcode

Aug 14th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 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', 'tab_category' => $category, 'orderby' => 'meta_value','order' => 'ASC')
  8.         );     
  9.            
  10.     $list = '
  11.     <script type="text/javascript">
  12.     jQuery(function() {
  13.     jQuery(".tabnav ul li:first-child")
  14.         .addClass("active")
  15.     });
  16.     </script>
  17.     <div class="col-12">
  18.         <div class="tabs vertical row">
  19.             <nav class="tabnav nav col-27">
  20.                 <ul>
  21.     ';
  22.    
  23.     while($q->have_posts()) : $q->the_post();
  24.         $idd = get_the_ID();
  25.         $list .= '
  26.             <li><a href="#">'.get_the_title().'</a></li>
  27.         ';        
  28.     endwhile;
  29.     $list.= '
  30.                 </ul>
  31.             </nav>
  32.     ';
  33.    
  34.    
  35.     while($q->have_posts()) : $q->the_post();
  36.         $idd = get_the_ID();
  37.         $list .= '
  38.             <div class="tab col-9">
  39.                 '.get_the_content().'
  40.             </div>
  41.         ';        
  42.     endwhile;
  43.     $list.= '
  44.         </div>
  45.     </div> 
  46.     ';
  47.     wp_reset_query();
  48.     return $list;
  49. }
  50. add_shortcode('tab', 'tab_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement