Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Advanced Search - Deisplay only Top Category in drop down

Advanced Search - Deisplay only Top Category in drop down

Views: 929

Results 1 to 3 of 3
31 Jul 2012, 6:27 PM
#1
sbbemn avatar

sbbemn

Zen Follower

Join Date:
Jan 2010
Posts:
182
Plugin Contributions:
0

Advanced Search - Deisplay only Top Category in drop down

Searched quite a bit for this, came close, but can't resolve this simple issue.

I'd like the category drop down in Advanced Search to only drop down the TOP categories only.

We have a 3 mile long list right now! Minimizing to the main top 16 would be great!

Thanks!

    <legend><?php echo ENTRY_CATEGORIES; ?></legend>
    <div class="floatLeft"><?php echo zen_draw_pull_down_menu('categories_id', zen_get_categories(array(array('id' => '', 'text' => TEXT_ALL_CATEGORIES)), '0' ,'', '1'), $sData['categories_id']); ?></div>
<?php echo zen_draw_checkbox_field('inc_subcat', '1', $sData['inc_subcat'], 'id="inc-subcat"'); ?><label class="checkboxLabel" for="inc-subcat"><?php echo ENTRY_INCLUDE_SUBCATEGORIES; ?></label>
31 Jul 2012, 8:48 PM
#2
sbbemn avatar

sbbemn

Zen Follower

Join Date:
Jan 2010
Posts:
182
Plugin Contributions:
0

Re: Advanced Search - Deisplay only Top Category in drop down

The drop down menu code is calling the zen_get_categories function

I could direct it to a new function of similar direction but need it to be limited to the top categories, no subcategories

Here is the zen_get_categories function

 function zen_get_categories($categories_array = '', $parent_id = '0', $indent = '', $status_setting = '') {
    global $db;

    if (!is_array($categories_array)) $categories_array = array();

    // show based on status
    if ($status_setting != '') {
      $zc_status = " c.categories_status='" . (int)$status_setting . "' and ";
    } else {
      $zc_status = '';
    }

    $categories_query = "select c.categories_id, cd.categories_name, c.categories_status
                         from " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
                         where " . $zc_status . "
                         parent_id = '" . (int)$parent_id . "'
                         and c.categories_id = cd.categories_id
                         and cd.language_id = '" . (int)$_SESSION['languages_id'] . "'
                         order by sort_order, cd.categories_name";

    $categories = $db->Execute($categories_query);

    while (!$categories->EOF) {
      $categories_array[] = array('id' => $categories->fields['categories_id'],
                                  'text' => $indent . $categories->fields['categories_name']);

      if ($categories->fields['categories_id'] != $parent_id) {
        $categories_array = zen_get_categories($categories_array, $categories->fields['categories_id'], $indent . '  ', '1');
      }
      $categories->MoveNext();
    }

    return $categories_array;
  }
31 Jul 2012, 9:41 PM
#3
sbbemn avatar

sbbemn

Zen Follower

Join Date:
Jan 2010
Posts:
182
Plugin Contributions:
0

Re: Advanced Search - Deisplay only Top Category in drop down

Here's the answer.

I duplicated the function "zen_get_categories" but directed it to zen_get_searchcategories, then found and commented out the code that displays the subcategories.

//  if ($categories->fields['categories_id'] != $parent_id) {
//   $categories_array = zen_get_categories($categories_array, $categories->fields['categories_id'], $indent . '  ', '1');
//  }