Skip to content

Instantly share code, notes, and snippets.

@KINKCreative
Last active August 29, 2015 14:28
Show Gist options
  • Save KINKCreative/ddd012faeed4f1f6cabd to your computer and use it in GitHub Desktop.
Save KINKCreative/ddd012faeed4f1f6cabd to your computer and use it in GitHub Desktop.
Pangolin - Category Accordion - Final
function category_accordion() {
?>
<?php
$args = array(
'number' => $number,
// 'orderby' => 'menu_order',
// 'order' => 'ASC',
'hide_empty' => $hide_empty,
'include' => $ids,
'parent' => 0
);
$parent_product_categories = get_terms( 'product_cat', $args );
$count = count($parent_product_categories);
if ( $count > 0 ) : ?>
<h3><?=__("Product Categories",'woocommerce');?></h3>
<div class="et_pb_accordion category_accordion">
<?php foreach ( $parent_product_categories as $parent_category ) :
$child_args = array(
'number' => $number,
'hide_empty' => $hide_empty,
'include' => $ids,
'parent' => $parent_category->term_id
);
$categories = get_terms( 'product_cat', $child_args );
$cat_prod_args = array(
'posts_per_page' => 12,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
// 'terms' => 'white-wines'
'terms' => $parent_category->slug
)
),
'post_type' => 'product',
'orderby' => 'menu_order'
);
$cat_products = new WP_Query( $cat_prod_args );
?>
<!-- Parent category start -->
<div class="et_pb_toggle et_pb_toggle_close">
<h4 class="">
<a href="<?php echo(get_term_link( $parent_category )); ?>">
<?php echo($parent_category->name); ?>
</a>
<? if(count($categories)>0 || $cat_products->post_count > 0) : ?>
<a href="#" class="et_pb_toggle_title" onClick="return: false;">
<i class="fa fa-angle-down"></i>
</a>
<?php else: ?>
<?php endif; ?>
</h4>
<div class="et_pb_toggle_content clearfix">
<? if(count($categories)>0) : ?>
<div class="et_pb_accordion category_accordion subcategory_accordion">
<?php foreach ( $categories as $category ) : ?>
<!-- subcategory block start -->
<div class="et_pb_toggle et_pb_toggle_close subcategory">
<h5 class="">
<a href="<?php echo(get_term_link( $category )); ?>">
<?php echo($category->name); ?>
</a>
<?php $args = array(
'posts_per_page' => 12,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
// 'terms' => 'white-wines'
'terms' => $category->slug
)
),
'post_type' => 'product',
'orderby' => 'menu_order'
);
$products = new WP_Query( $args ); ?>
<a href="#" class="et_pb_toggle_title">
<?php if(sizeof($products)>0) : ?>
<i class="fa fa-angle-down"></i>
<?php else : ?>
<i class="fa fa-angle-right"></i>
<?php endif; ?>
</a>
</h5>
<?php if(sizeof($products)>0) : ?>
<div class="et_pb_toggle_content clearfix">
<ul>
<?php while ( $products->have_posts() ) :
$products->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
</div><!-- end et_pb_toggle_content -->
<?php endif; ?>
</div><!-- end et_pb_toggle -->
<?php endforeach; ?>
</div><!-- end .et_pb_accordion.subcategory -->
<?php else: ?>
<ul>
<?php while ( $cat_products->have_posts() ) :
$cat_products->the_post(); ?>
<li>
<a href="<?php the_permalink(); ?>">
<?php the_title(); ?>
</a>
</li>
<?php endwhile; ?>
</ul>
<?php endif; ?>
</div><!-- end et_pb_toggle_content -->
</div>
<?php endforeach; ?>
</div><!-- end .subcategory accordion -->
<?php endif; ?>
<?
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment