Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @@ Markup PHP
- ______________________________
- <ul id="custom_accordion">
- <?php
- $terms = get_terms('product_cat');
- if ( !empty( $terms ) && !is_wp_error( $terms ) ){
- foreach( get_terms( 'product_cat', array( 'hide_empty' => false, 'parent' => 0 ) ) as $parent_term ) {
- $term_children = get_term_children($parent_term->term_id, 'product_cat');
- if ($term_children) { ?>
- <li class="header-menu-item parent">
- <a href="<?php echo esc_attr(get_term_link($parent_term, 'product_cat')); ?>"><?php echo $parent_term->name; ?></a>
- <span class="li_has_child"></span>
- <ul class="child_ul">
- <?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 ) {
- $term_children_child = get_term_children($child_term->term_id, 'product_cat');
- if ($term_children_child) { ?>
- <li class="header-menu-item parent">
- <a href="<?php echo esc_attr(get_term_link($child_term, 'product_cat')); ?>"><?php echo $child_term->name; ?></a>
- <span class="li_has_child"></span>
- <ul class="child_ul">
- <?php foreach( get_terms( 'product_cat', array('child_of' => $child_term->term_id, 'orderby' => 'group_name', 'hide_empty' => false) ) as $child_child_term ) {
- $term_children_child_child = get_term_children($child_child_term->term_id, 'product_cat');
- if ($term_children_child) {
- ?>
- <li class="header-menu-item parent">
- <a href="<?php echo esc_attr(get_term_link($child_child_term, 'product_cat')); ?>"><?php echo $child_child_term->name; ?></a>
- <span class="li_has_child"></span>
- </li>
- <?php } else { ?>
- <li class="header-menu-item">
- <a href="<?php echo home_url(); ?>/products/<?php echo $child_child_term->slug; ?>"><?php echo $child_child_term->name; ?></a>
- </li>
- <?php }} ?>
- </ul>
- </li>
- <?php } else { ?>
- <li class="header-menu-item">
- <a href="<?php echo esc_attr(get_term_link($child_term, 'product_cat')); ?>"><?php echo $child_term->name; ?></a>
- </li>
- <?php }} ?>
- </ul>
- </li>
- <?php } else { ?>
- <li class="header-menu-item">
- <a href="<?php echo home_url(); ?>/products/<?php echo $parent_term->slug; ?>"><?php echo $parent_term->name; ?></a>
- </li>
- <?php }
- ?>
- <?php }
- } ?>
- </ul>
- @@ CSS (Not Completed but need altest this css to init accordion)
- _______________________________
- #custom_accordion li ul {
- display: none;
- }
- #custom_accordion {
- width: 350px;
- }
- #custom_accordion li {
- position: relative;
- }
- .li_has_child {
- background-color: black;
- cursor: pointer;
- height: 20px;
- position: absolute;
- right: 0;
- width: 20px;
- z-index: 3;
- }
- @@ jQuery
- ______________________________
- jQuery(document).ready(function () {
- jQuery("#custom_accordion li span").click(function(){
- if(false == jQuery(this).next().is(':visible')) {
- jQuery('#custom_accordion li ul').slideUp(300);
- }
- jQuery(this).next().slideToggle(300);
- });
- jQuery('#custom_accordion li ul:eq(0)').show();
- });
Advertisement
Add Comment
Please, Sign In to add comment