added category files and display category list
authorAnthony Talarico <talarico@gaslightmedia.com>
Wed, 16 Dec 2015 21:50:06 +0000 (16:50 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Wed, 16 Dec 2015 21:50:06 +0000 (16:50 -0500)
index.php
views/category_detail.php [new file with mode: 0644]
views/list_categories.php [new file with mode: 0644]
views/list_products.php
views/product_detail.php

index 21024c9..9bcea20 100644 (file)
--- 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 (file)
index 0000000..bed95df
--- /dev/null
@@ -0,0 +1,2 @@
+<h2><?php echo $term->name; ?></h2>
diff --git a/views/list_categories.php b/views/list_categories.php
new file mode 100644 (file)
index 0000000..3220d78
--- /dev/null
@@ -0,0 +1,12 @@
+  
+<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>
index af95346..c0d4a36 100644 (file)
@@ -3,7 +3,12 @@
         <div class="small-12 medium-3 columns<?php if ($product->end){ echo ' end';}?>">
         <a href="<?php echo $product->href; ?>">
                 <?php echo $product->post_title; ?>
+           
             </a>
+            
         </div>
     <?php endforeach; endif; ?>
+   
+     
 </div>
+
index 2ded421..f5abca6 100644 (file)
@@ -1,2 +1,3 @@
 <h2><?php echo $product->post_title; ?></h2>
     <?php echo $product->post_content; ?>
+