From 43b81f0ae9c745ff60645d1bd1d590c8bad6d5aa Mon Sep 17 00:00:00 2001 From: Anthony Talarico Date: Wed, 16 Dec 2015 16:50:06 -0500 Subject: [PATCH] added category files and display category list --- index.php | 43 ++++++++++++++++++++++++++++++++++++++- views/category_detail.php | 2 ++ views/list_categories.php | 12 +++++++++++ views/list_products.php | 5 +++++ views/product_detail.php | 1 + 5 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 views/category_detail.php create mode 100644 views/list_categories.php diff --git a/index.php b/index.php index 21024c9..9bcea20 100644 --- a/index.php +++ b/index.php @@ -158,6 +158,7 @@ function michsci_taxonomy_filter_post_type_request( $query ) } } } + } add_filter( 'parse_query', 'michsci_taxonomy_filter_post_type_request' ); @@ -172,8 +173,13 @@ function michsci_shortcode($atts) 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(); @@ -223,6 +229,34 @@ function michsci_list_products() 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) { @@ -231,4 +265,11 @@ 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' ); diff --git a/views/category_detail.php b/views/category_detail.php new file mode 100644 index 0000000..bed95df --- /dev/null +++ b/views/category_detail.php @@ -0,0 +1,2 @@ +

name; ?>

+ diff --git a/views/list_categories.php b/views/list_categories.php new file mode 100644 index 0000000..3220d78 --- /dev/null +++ b/views/list_categories.php @@ -0,0 +1,12 @@ + +
+ + + + + +
diff --git a/views/list_products.php b/views/list_products.php index af95346..c0d4a36 100644 --- a/views/list_products.php +++ b/views/list_products.php @@ -3,7 +3,12 @@
post_title; ?> + +
+ + + diff --git a/views/product_detail.php b/views/product_detail.php index 2ded421..f5abca6 100644 --- a/views/product_detail.php +++ b/views/product_detail.php @@ -1,2 +1,3 @@

post_title; ?>

post_content; ?> + -- 2.17.1