adjusting dropdown for shortcode
authorAnthony Talarico <talarico@gaslightmedia.com>
Tue, 12 Jan 2016 19:08:08 +0000 (14:08 -0500)
committerAnthony Talarico <talarico@gaslightmedia.com>
Tue, 12 Jan 2016 19:08:08 +0000 (14:08 -0500)
index.php
views/list_categories.php
views/list_products.php

index 908eba6..d9b29f9 100644 (file)
--- a/index.php
+++ b/index.php
@@ -441,12 +441,13 @@ function michsci_shortcode($atts)
     if ( isset($atts['cat']) ) {
         if ($prodCategory = get_term_by( 'slug', $atts['cat'], MICHSCI_CATEGORY_NAME ) ) {
             $_REQUEST[MICHSCI_CATEGORY_NAME] = $prodCategory->term_id;
+            $cat_id = $_REQUEST[MICHSCI_CATEGORY_NAME];
+            
         }
     }
-
     echo '<form id="catSubmit" action=""><div class="row catSearch"><div id="viewBtns" class="12-small medium-3 columns"> <button id="grid" type="button">Grid</button> <button id="list"type="button">list</button>
              <span id="productSearch"> Search Products</span></div><div id="catDropdown" class="small-12 medium-4 columns">';
-    echo michsci_get_terms_dropdown();
+    echo michsci_get_terms_dropdown($cat_id);
     echo '</div><div id="searchContainer" class="small-12 medium-3 columns"></form> <form class="searchform" role="search" method="get" action="' .get_bloginfo('url') .'">
          <input class="search-input" placeholder="SEARCH" value="" name="s" type="text">
          <input id="input" class="search-button" name="searchButton" value="Search" type="submit">
@@ -477,9 +478,23 @@ function michsci_shortcode($atts)
  * @access public
  * @return void
  */
-function michsci_get_terms_dropdown()
+function michsci_get_terms_dropdown($cat_id)
 {
     $taxonomyName = MICHSCI_CATEGORY_NAME;
+    if($cat_id){
+        $cats_child = get_term_children($cat_id, $taxonomyName);
+        foreach($cats_child as $cat){
+         $output ="<select id='categoryDropdown' name=\"" . MICHSCI_CATEGORY_NAME . "\"><option value=\"\">Select " . MICHSCI_CATEGORY_SINGLE . "</option>";
+        $main = get_term($cat_id, MICHSCI_CATEGORY_NAME);
+          $output .= '<option value="' . $cat . '"';
+           if ($_REQUEST[MICHSCI_CATEGORY_NAME] == $cat->term_id) {
+                $output .= ' selected';
+            }
+            $catName = get_term($cat, MICHSCI_CATEGORY_NAME);
+             $output .= '>' . $catName->name. '</option>';
+         $output .="</select>";
+        }
+    } else {
     $parent_terms = get_terms($taxonomyName, array('parent' => 0, 'orderby' => 'name', 'hide_empty' => false));
     $output ="<select id='categoryDropdown' name=\"" . MICHSCI_CATEGORY_NAME . "\"><option value=\"\">Select " . MICHSCI_CATEGORY_SINGLE . "</option>";
         // get parent categories
@@ -498,16 +513,9 @@ function michsci_get_terms_dropdown()
                     $output .= ' selected';
                 }
                 $output .= '>' . "&nbsp&nbsp&nbsp" .  $child->name . '</option>';
-//                foreach($grandchildren as $grandchild){
-//                    $output .= '<option value="' . $grandchild->term_id . '"';
-//                    if ($_REQUEST[MICHSCI_CATEGORY_NAME] == $grandchild->term_id) {
-//                        $output .= ' selected';
-//                    }
-//                    $output .= '>' . "&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp" .  $grandchild->name . '</option>';
-//                }
             }
         }
-    $output .="</select>";
+    $output .="</select>"; }
     return $output;
 }
 
index 0971b44..023b4c5 100644 (file)
@@ -1,12 +1,6 @@
 <?php if(!isset($_COOKIE['catView']) || $_COOKIE['catView'] == "grid"){ ?>
 <div id="categoriesGridView" class="row">
-    <?php $uri= $_SERVER['REQUEST_URI']; 
-      $catNum = substr($uri, -2);
-      if(is_numeric($catNum) == false){
-          $catNum = substr($catNum, -1);
-      }
-      echo category_description($catNum);
-   ?>
+
 <?php
     if ( isset( $taxonomy_terms) && is_array( $taxonomy_terms ) ) :
         foreach ( $taxonomy_terms  as $term ) : ?>
@@ -21,7 +15,6 @@
                  <a href="<?php echo $term->href; ?>"> <?php echo $term->name; ?> </a>
              </div>
         </div>
-               
             </div>
         </div>
     <?php
 <?php } ?>
 <?php if(!isset($_COOKIE['catView']) || $_COOKIE['catView'] == "list"){ ?>
 <div id="categoriesListView" class="row">
-     <?php $uri= $_SERVER['REQUEST_URI']; 
-      $catNum = substr($uri, -2);
-      if(is_numeric($catNum) == false){
-          $catNum = substr($catNum, -1);
-      }
-      echo category_description($catNum);
-   ?>
+
 <?php
     if ( isset( $taxonomy_terms) && is_array( $taxonomy_terms ) ) :
         foreach ( $taxonomy_terms  as $term ) : ?>
index 6b5b37b..b58306f 100644 (file)
@@ -2,15 +2,13 @@
 
 <?php if(!isset($_COOKIE['view']) || $_COOKIE['view'] == "grid"){ ?>
     <div id="gridView" class="row">
-    <?php $uri= $_SERVER['REQUEST_URI']; 
-      $catNum = substr($uri, -2);
-      if(is_numeric($catNum) == false){
-          $catNum = substr($catNum, -1);
-      }
+    <?php 
+    
+      $catNum = $_REQUEST[MICHSCI_CATEGORY_NAME];
       echo category_description($catNum);
+  
    ?>
     <?php if ( isset( $products ) && is_array( $products ) ) : foreach ( $products as $product ) : ?>
-        
    <?php $tags = wp_get_post_terms($product->ID,'michsci_tag'); ?>
         <div class="<?php foreach ($tags as $tag)echo $tag->slug . " ";?> product grid small-12 medium-4 columns<?php if ($product->end){ echo ' end';}?>">
 
 
 <?php if($_COOKIE['view'] == "list"){ ?>
    <div id="listView" class="row">
-   <?php $uri= $_SERVER['REQUEST_URI']; 
-      $catNum = substr($uri, -2);
-      if(is_numeric($catNum) == false){
-          $catNum = substr($catNum, -1);
-      }
+   <?php 
+      $catNum = $_REQUEST[MICHSCI_CATEGORY_NAME];
       echo category_description($catNum);
    ?>
     <?php if ( isset( $products ) && is_array( $products ) ) : foreach ( $products as $product ) : ?>