Itgyaanhin

Untitled

Apr 13th, 2015
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1. @@ Markup PHP
  2. ______________________________
  3.  
  4. <ul id="custom_accordion">
  5.  
  6. <?php
  7. $terms = get_terms('product_cat');
  8. if ( !empty( $terms ) && !is_wp_error( $terms ) ){
  9. foreach( get_terms( 'product_cat', array( 'hide_empty' => false, 'parent' => 0 ) ) as $parent_term ) {
  10.  
  11. $term_children = get_term_children($parent_term->term_id, 'product_cat');
  12. if ($term_children) { ?>
  13. <li class="header-menu-item parent">
  14. <a href="<?php echo esc_attr(get_term_link($parent_term, 'product_cat')); ?>"><?php echo $parent_term->name; ?></a>
  15. <span class="li_has_child"></span>
  16.  
  17. <ul class="child_ul">
  18. <?php foreach( get_terms( 'product_cat', array('child_of' => $parent_term->term_id, 'parent' => $parent_term->term_id, 'orderby' => 'group_name', 'hide_empty' => false) ) as $child_term ) {
  19. $term_children_child = get_term_children($child_term->term_id, 'product_cat');
  20. if ($term_children_child) { ?>
  21. <li class="header-menu-item parent">
  22. <a href="<?php echo esc_attr(get_term_link($child_term, 'product_cat')); ?>"><?php echo $child_term->name; ?></a>
  23. <span class="li_has_child"></span>
  24. <ul class="child_ul">
  25. <?php foreach( get_terms( 'product_cat', array('child_of' => $child_term->term_id, 'orderby' => 'group_name', 'hide_empty' => false) ) as $child_child_term ) {
  26. $term_children_child_child = get_term_children($child_child_term->term_id, 'product_cat');
  27. if ($term_children_child) {
  28. ?>
  29. <li class="header-menu-item parent">
  30. <a href="<?php echo esc_attr(get_term_link($child_child_term, 'product_cat')); ?>"><?php echo $child_child_term->name; ?></a>
  31. <span class="li_has_child"></span>
  32. </li>
  33. <?php } else { ?>
  34. <li class="header-menu-item">
  35. <a href="<?php echo home_url(); ?>/products/<?php echo $child_child_term->slug; ?>"><?php echo $child_child_term->name; ?></a>
  36. </li>
  37. <?php }} ?>
  38. </ul>
  39. </li>
  40. <?php } else { ?>
  41. <li class="header-menu-item">
  42. <a href="<?php echo esc_attr(get_term_link($child_term, 'product_cat')); ?>"><?php echo $child_term->name; ?></a>
  43. </li>
  44. <?php }} ?>
  45. </ul>
  46. </li>
  47. <?php } else { ?>
  48. <li class="header-menu-item">
  49. <a href="<?php echo home_url(); ?>/products/<?php echo $parent_term->slug; ?>"><?php echo $parent_term->name; ?></a>
  50. </li>
  51.  
  52. <?php }
  53. ?>
  54.  
  55. <?php }
  56. } ?>
  57.  
  58. </ul>
  59.  
  60.  
  61. @@ CSS (Not Completed but need altest this css to init accordion)
  62. _______________________________
  63. #custom_accordion li ul {
  64. display: none;
  65. }
  66. #custom_accordion {
  67. width: 350px;
  68. }
  69. #custom_accordion li {
  70. position: relative;
  71. }
  72. .li_has_child {
  73. background-color: black;
  74. cursor: pointer;
  75. height: 20px;
  76. position: absolute;
  77. right: 0;
  78. width: 20px;
  79. z-index: 3;
  80. }
  81.  
  82.  
  83.  
  84. @@ jQuery
  85. ______________________________
  86. jQuery(document).ready(function () {
  87. jQuery("#custom_accordion li span").click(function(){
  88.  
  89. if(false == jQuery(this).next().is(':visible')) {
  90. jQuery('#custom_accordion li ul').slideUp(300);
  91. }
  92. jQuery(this).next().slideToggle(300);
  93. });
  94.  
  95. jQuery('#custom_accordion li ul:eq(0)').show();
  96. });
Advertisement
Add Comment
Please, Sign In to add comment