Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / replace categories menu with ul/li

replace categories menu with ul/li

Locked

Views: 3,182

Results 1 to 7 of 7
This thread is locked. New replies are disabled.
27 Jul 2007, 11:00 AM
#1
christoph_lutz avatar

christoph_lutz

New Zenner

Join Date:
Jun 2007
Posts:
24
Plugin Contributions:
0

replace categories menu with ul/li

Hi,

This may have been asked before but I just can't find it anywhere. I am trying to replace the categories sidebox display with a 'proper' ul/li structure. I want to keep the standard functionality where subcategories open after a top level category has been selected. The better categories mods I have seen all show all items at all times which is not what I want. Has anyone dones this or is there a mod that is available?

Thanks

Christoph

27 Jul 2007, 1:36 PM
#2
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: replace categories menu with ul/li

Categories Dressing simulates the function of a <ul> structure (using display: list-item;), but is not actually a list because that would not allow some of the other functionality included in it. There is considerable discussion in the readme that may help you adapt tpl_categories.php to a <ul> structure if that is all you want it to do.

27 Jul 2007, 3:29 PM
#3
christoph_lutz avatar

christoph_lutz

New Zenner

Join Date:
Jun 2007
Posts:
24
Plugin Contributions:
0

Re: replace categories menu with ul/li

Hi,

Thanks very much for the reply. I downloaded the mod and looked through the readme. It seems that there is a lot that can be done via this mod but I'd still prefer to start with a 'clean' ul/li structure and apply styles to those.

Anyone else?

Thanks

Christoph

5 Apr 2009, 10:34 AM
#4
vandiermen avatar

vandiermen

Totally Zenned

Join Date:
Feb 2007
Posts:
518
Plugin Contributions:
1

Re: replace categories menu with ul/li

/includes/templates/template_default/sideboxes/tpl_categories.php

 
<?php
/**
 * Side Box Template
 *
 * @package templateSystem
 * @copyright Copyright 2003-2006 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_categories.php 4162 2006-08-17 03:55:02Z ajeh $
 */
  $content = "";
 
  $content .= '<div id="' . str_replace('_', '-', $box_id . 'Content') . '" class="sideBoxContent">' . "\n";
  $content .= '<ul>' . "\n";
 
  for ($i=0;$i<sizeof($box_categories_array);$i++) {
    switch(true) {
// to make a specific category stand out define a new class in the stylesheet example: A.category-holiday
// uncomment the select below and set the cPath=3 to the cPath= your_categories_id
// many variations of this can be done
//      case ($box_categories_array[$i]['path'] == 'cPath=3'):
//        $new_style = 'category-holiday';
//        break;
      case ($box_categories_array[$i]['top'] == 'true'):
        $new_style = 'category-top';
        break;
      case ($box_categories_array[$i]['has_sub_cat']):
        $new_style = 'category-subs';
        break;
      default:
        $new_style = 'category-products';
      }
     if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == 3 or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
        // skip if this is for the document box (==3)
      } else {
      $content .= '<li>';
      $content .= '<a class="' . $new_style . '" href="' . zen_href_link(FILENAME_DEFAULT, $box_categories_array[$i]['path']) . '">';
      if ($box_categories_array[$i]['current']) {
        if ($box_categories_array[$i]['has_sub_cat']) {
          $content .= '<span class="category-subs-parent">' . $box_categories_array[$i]['name'] . '</span>';
        } else {
          $content .= '<span class="category-subs-selected">' . $box_categories_array[$i]['name'] . '</span>';
        }
      } else {
        $content .= $box_categories_array[$i]['name'];
      }
      if ($box_categories_array[$i]['has_sub_cat']) {
        $content .= CATEGORIES_SEPARATOR;
      }
      $content .= '</a>';
      if (SHOW_COUNTS == 'true') {
        if ((CATEGORIES_COUNT_ZERO == '1' and $box_categories_array[$i]['count'] == 0) or $box_categories_array[$i]['count'] >= 1) {
          $content .= CATEGORIES_COUNT_PREFIX . $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX;
        }
      }
 
      $content .= '</li>';
 
    }
  }
      $content .= '</ul>' . "\n";
  if (SHOW_CATEGORIES_BOX_SPECIALS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true' or SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true' or SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
// display a separator between categories and links
    if (SHOW_CATEGORIES_SEPARATOR_LINK == '1') {
      $content .= '<hr id="catBoxDivider" />' . "\n";
    }
 
  $content .= '<div class="box_body_2"><ul>'; 
 
 
    if (SHOW_CATEGORIES_BOX_SPECIALS == 'true') {
      $show_this = $db->Execute("select s.products_id from " . TABLE_SPECIALS . " s where s.status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<li><a class="category-links" href="' . zen_href_link(FILENAME_SPECIALS) . '">' . CATEGORIES_BOX_HEADING_SPECIALS . '</a></li>' . "\n";
      }
    }
 
    if (SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') {
      // display limits
//      $display_limit = zen_get_products_new_timelimit();
      $display_limit = zen_get_new_date_range();
      $show_this = $db->Execute("select p.products_id
                                 from " . TABLE_PRODUCTS . " p
                                 where p.products_status = 1 " . $display_limit . " limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<li><a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_NEW) . '">' . CATEGORIES_BOX_HEADING_WHATS_NEW . '</a></li>' . "\n";
      }
    }
 
    if (SHOW_CATEGORIES_BOX_FEATURED_PRODUCTS == 'true') {
      $show_this = $db->Execute("select products_id from " . TABLE_FEATURED . " where status= 1 limit 1");
      if ($show_this->RecordCount() > 0) {
        $content .= '<li><a class="category-links" href="' . zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' . CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS . '</a></li>' . "\n";
      }
    }
 
    if (SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
      $content .= '<li><a class="category-links" href="' . zen_href_link(FILENAME_PRODUCTS_ALL) . '">' . CATEGORIES_BOX_HEADING_PRODUCTS_ALL . '</a></li>' . "\n";
    }
 
 $content .= '</ul></div>'; 
 
  }
  $content .= '</div>';
?>
 
 
5 Apr 2009, 10:48 AM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: replace categories menu with ul/li

Good start, though this doesn't take into account the nested lists that would be needed to correctly show subcategories.

Categories Dressing is now constructed on a (nested) <ul> structure, for anyone who is interested.

5 Apr 2009, 1:19 PM
#6
vandiermen avatar

vandiermen

Totally Zenned

Join Date:
Feb 2007
Posts:
518
Plugin Contributions:
1

Re: replace categories menu with ul/li

Also need to:
In your Admin area select:
Configuration --> My Store --> Show Category Counts --> edit
set this to false.

Seems to work 100% fine in v1.3.8, no problems here with subcategories

5 Apr 2009, 4:58 PM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: replace categories menu with ul/li

You make one list for categories, and all top and subcategories are equal items in the list. This is not the way a <ul> is supposed to work; there should be nested lists for the subcats.