RUSSEL86

Custom tab with dynamic

Dec 2nd, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. // html code
  2. --------------------
  3. <div class="hire_tab_main_area">
  4. <div class="hire_tab_list">
  5. <ul class="tabs">
  6. <li class="tab-link current" data-tab="tab-1">Tab One</li>
  7. <li class="tab-link" data-tab="tab-2">Tab Two</li>
  8. <li class="tab-link" data-tab="tab-3">Tab Three</li>
  9. <li class="tab-link" data-tab="tab-4">Tab Four</li>
  10. </ul>
  11. </div>
  12. <div class="hire_tab_content">
  13. <div id="tab-1" class="tab-content current">
  14. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  15. </div>
  16. <div id="tab-2" class="tab-content">
  17. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  18. </div>
  19. <div id="tab-3" class="tab-content">
  20. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
  21. </div>
  22. <div id="tab-4" class="tab-content">
  23. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
  24. </div>
  25. </div>
  26. </div>
  27.  
  28. //css code
  29. ---------------------
  30. .hire_tab_main_area{
  31. margin-bottom: 10px;
  32. float: left;
  33. }
  34. .hire_tab_list{
  35. float: left;
  36. width: 28%;
  37. margin-right: 1%;
  38. }
  39. .hire_tab_list ul.tabs{}
  40. .hire_tab_list ul.tabs li{
  41. display: block;
  42. background: #888;
  43. color: #000;
  44. font-size: 12px !important;
  45. }
  46. .hire_tab_content{
  47. float: left;
  48. width: 71%;
  49. }
  50. .hire_tab_content .tab-content{}
  51. .tab_content_title{}
  52. .tab_content_title h1{}
  53.  
  54. ul.tabs{
  55. margin: 0px;
  56. padding: 0px;
  57. list-style: none;
  58. }
  59. ul.tabs li{
  60. background: none;
  61. color: #fff;
  62. display: inline-block;
  63. padding: 0 5px;
  64. cursor: pointer;
  65. border: 1px solid;
  66. }
  67.  
  68. ul.tabs li.current{
  69. background: #ccc;
  70. color: #222;
  71. }
  72.  
  73. .tab-content{
  74. display: none;
  75. padding: 0 5px;
  76. line-height: 20px;
  77. }
  78.  
  79. .tab-content.current{
  80. display: inherit;
  81. }
  82.  
  83. // jquery code
  84. ------------------
  85. jQuery('ul.tabs li').click(function(){
  86. var tab_id = jQuery(this).attr('data-tab');
  87.  
  88. jQuery('ul.tabs li').removeClass('current');
  89. jQuery('.tab-content').removeClass('current');
  90.  
  91. jQuery(this).addClass('current');
  92. jQuery("#"+tab_id).addClass('current');
  93. })
  94.  
  95.  
  96. // dynamic code with shortcode
  97. ---------------------
  98. function krproduct_shortcode($atts){
  99.  
  100. ob_start();
  101.  
  102. extract( shortcode_atts( array(
  103. ), $atts, 'product' ) );
  104.  
  105. ?>
  106.  
  107.  
  108. <div class="hire_tab_main_area">
  109. <div class="hire_tab_list">
  110. <ul class="tabs">
  111. <?php $ctr = 0;
  112. $my_query = new WP_Query(array(
  113. 'post_type' => 'product-items',
  114. 'posts_per_page' => -1,
  115. 'order' => 'ASC',
  116. ));
  117. if($my_query->have_posts()):
  118. while($my_query->have_posts()): $my_query->the_post();
  119. $class = $ctr == 0 ? ' current' : ''; ?>
  120.  
  121. <li class="tab-link <?php echo $class; ?>" data-tab="tab-<?php the_ID(); ?>"><?php the_title();?></li>
  122.  
  123. <?php $ctr++;
  124. endwhile; endif; wp_reset_query(); ?>
  125. </ul>
  126. </div>
  127. <div class="hire_tab_content">
  128.  
  129. <?php $ctrcont = 0;
  130. $tab_query = new WP_Query(array(
  131. 'post_type' => 'product-items',
  132. 'posts_per_page' => -1,
  133. 'order' => 'ASC',
  134. ));
  135. if($tab_query->have_posts()):
  136. while($tab_query->have_posts()): $tab_query->the_post();
  137. $class = $ctrcont == 0 ? ' current' : ''; ?>
  138.  
  139. <div id="tab-<?php the_ID(); ?>" class="tab-content <?php echo $class; ?>">
  140. <div class="tab_content_title">
  141. <h1><?php //the_title();?></h1>
  142. </div>
  143.  
  144. <?php the_content();?>
  145. </div>
  146.  
  147. <?php $ctrcont++;
  148. endwhile; endif; wp_reset_query(); ?>
  149.  
  150. </div>
  151. </div>
  152.  
  153.  
  154. <?php wp_reset_postdata();
  155. return ob_get_clean();
  156. }
  157. add_shortcode('product_tab', 'krproduct_shortcode');
Advertisement
Add Comment
Please, Sign In to add comment