Skip to content

Instantly share code, notes, and snippets.

@calliaweb
Created October 7, 2014 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calliaweb/bc7d4196008d597e2d50 to your computer and use it in GitHub Desktop.
Save calliaweb/bc7d4196008d597e2d50 to your computer and use it in GitHub Desktop.
Show sub categories
<?php
// If sub categories don't show products only show sub categories.
remove_action( 'genesis_loop', 'genesis_do_loop' );
add_action( 'genesis_loop', 'jmw_sub_categories_loop' );
function jmw_sub_categories_loop() {
// Are there sub categories?
$term_object = get_queried_object();
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'parent' => $term_object->term_id,
'hide_empty' => false,
);
// If there is show them but no products
if ( $sub_terms = get_terms( 'product-category', $args ) ) {
foreach( $sub_terms as $sub_term ) {
$class = "entry one-third";
printf( '<article class="%s" itemtype="http://schema.org/CreativeWork" itemscope="itemscope"><h2 class="entry-title" iteprop="headline"><a rel="bookmark" title="%s" href="%s">%s</a></h2><div class="entry-content" itemprop="text">%s<p><a class="more-link" href="%s"><span class="screen-reader-text">%s</span>Find out more &raquo;</a></p></div></article>',
$class,
$sub_term->name,
get_term_link( $sub_term ),
$sub_term->name,
apply_filters( 'the_content', $sub_term->description ),
get_term_link( $sub_term ),
$sub_term->name
);
}
}
else { // show the products
genesis_do_loop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment