}
}
}
+
}
add_filter( 'parse_query', 'michsci_taxonomy_filter_post_type_request' );
if ( $product_id = filter_var( $_REQUEST['product'] ) ) {
michsci_show_product($product_id);
- } else {
+
+ } if($cat_id = filter_var( $_REQUEST['term'])) {
+ michsci_show_category($cat_id);
+ }
+ else {
michsci_list_products();
+ michsci_list_categories();
}
$output = ob_get_contents();
include 'views/list_products.php';
return;
}
+function michsci_list_categories()
+{
+ global $wpdb, $wp;
+
+ $taxonomy = 'michsci_category';
+ $taxonomy_terms = get_terms( $taxonomy, array(
+ 'hide_empty' => false,
+ 'parent'=> 0) );
+
+
+ $totalTerms = count( $taxonomy_terms);
+ $current_url = esc_url( add_query_arg( $wp->query_string, '', home_url( $wp->request ) ) );
+ $iterator = 1;
+
+ foreach ( $taxonomy_terms as $term) {
+ $term->end = false;
+ if ( $iterator == $totalTerms) {
+ $term->end = true;
+ }
+ $term->href = $current_url
+ . ( ( strpos( $current_url, '?' ) ) ? '&' : '?' )
+ . "category=" . $term->term_id;
+ ++$iterator;
+ }
+
+ include 'views/list_categories.php';
+ return;
+}
function michsci_show_product($prod_id)
{
include 'views/product_detail.php';
return;
}
+function michsci_show_category($cat_id)
+{
+ global $wpdb, $wp;
+ $term = get_terms( $cat_id );
+ include 'views/category_detail.php';
+ return;
+}
add_shortcode( 'michproducts', 'michsci_shortcode' );
--- /dev/null
+
+<div class="row">
+
+ <?php if ( isset( $taxonomy_terms) && is_array( $taxonomy_terms ) ) : foreach ( $taxonomy_terms as $term ) : ?>
+ <div class="small-12 medium-3 columns<?php if ($term->end){ echo ' end';}?>">
+ <a href="<?php echo $term->href; ?>">
+ <?php echo $term->name; ?>
+ </a>
+ </div>
+ <?php endforeach; endif; ?>
+
+</div>