Results 1 to 10 of 14

Hybrid View

  1. #1
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Help nesting products under categories in side bar

    OK, I just looked at your BEGIN and END... Tags there will do you no good of any kind.

    What you need to do is build code that will determine when the category nesting level changes, and insert <ul> or </ul> tags as appropriate. I started working on this for Categories Dressing, but shelved it because it could not really provide an advantage as long as people use IE6, which will not allow :hover to affect anything that is not an <a> tag.

    You can get the current category depth by counting the number of underscores _ in $box_categories_id[$i][path]. Comparing that to the previous number and calculating how many of what to insert should not be that difficult. It also needs an exit calculation, to know how many </ul> to insert if the last item is a subcat.

  2. #2
    Join Date
    Dec 2007
    Posts
    23
    Plugin Contributions
    0

    Default Re: Help nesting products under categories in side bar

    Hey gjh42,

    Thanks for your prompt responses. The problem is, I'm not that talented with PHP, is there anyway you could help me out to solve this problem, I will pay you if need it be? This is very important for me to be done. Thanks.

  3. #3
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Help nesting products under categories in side bar

    You have the "indent" statement formulated incorrectly:

    $indent = str_repeat($box_categories_array[$i]['level']+1);

    should be:

    PHP Code:
    $indent str_repeat(CATEGORIES_SUBCATEGORIES_INDENT,$box_categories_array[$i]['level']+1); 

    I have the ul nesting code worked out, but not yet tested, for a standard tpl_categories.php.

    However, you are using a mod that not only significantly reworks the coding of the list section, but uses information not available to the standard version. I think it would actually make calculating the nesting easier, but I'm reluctant to use it without knowing something about it, and it would make the code dependent on your mod version.

    Accounting for the products in the nesting will require the use of some of the non-standard info, but it will be impossible for me to test that part.

    I'll post the nesting code additions once I get them typed in.

  4. #4
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Help nesting products under categories in side bar

    This is a standard tpl_categories.php modified to use <ul> lists for all categories and links.

    Tested and works correctly, though some stylesheet changes are needed for good appearance.
    PHP Code:
    <?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 $ gjh42 2007-12-21 - limit subcats, ul code
     */
      
    $content "";
      
      
    $content .= '<div id="' str_replace('_''-'$box_id 'Content') . '" class="sideBoxContent">' "\n";
      
    //ul code setup
      
    $ul_now 0;
      
    $end_ul_now 0;
      
    $prev_cat_depth 0;
      
    $content .= '<ul>';
      
    // /ul code setup
      
    for ($i=0;$i<sizeof($box_categories_array);$i++) {
        
    $cat_depth substr_count($box_categories_array[$i]['path'],'_');//ul code
        
    if ($cat_depth $prev_cat_depth) {
          
    //$ul_now = $cat_depth - $prev_cat_depth;//probably unnecessary
          
    $content .= '<ul>';//should only ever be 1 ul here
        
    } elseif ($cat_depth $prev_cat_depth) {
          
    $end_ul_now $prev_cat_depth $cat_depth;
          
    $content .= ($end_ul_now != 0)?str_repeat('</ul>',$end_ul_now):'';
        }
        
    $prev_cat_depth $cat_depth;// /ul code

        
    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';
          }
     
    // subcat limit test 20071220   if (substr_count($box_categories_array[$i]['path'],'_') > 1 or 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)) {
         
    if (zen_get_product_types_to_category($box_categories_array[$i]['path']) == or ($box_categories_array[$i]['top'] != 'true' and SHOW_CATEGORIES_SUBCATEGORIES_ALWAYS != 1)) {
            
    // skip if this is for the document box (==3)
          
    } else {
          
    $content .= /*ul code*/'<li><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 .= /*ul code*/'</li>' "\n";
        }
      }
      
    $content .= str_repeat('</ul>',$cat_depth+1);//ul code

      
    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 .= /*ul code*/'<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 .= /*ul code*/'<li><a class="category-links" href="' zen_href_link(FILENAME_SPECIALS) . '">' CATEGORIES_BOX_HEADING_SPECIALS '</a>' /*ul code*/'</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 .= /*ul code*/'<li><a class="category-links" href="' zen_href_link(FILENAME_PRODUCTS_NEW) . '">' CATEGORIES_BOX_HEADING_WHATS_NEW '</a>' /*ul code*/'</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 .= /*ul code*/'<li><a class="category-links" href="' zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS '</a>' /*ul code*/'</li>' "\n";
          }
        }
        if (
    SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
          
    $content .= /*ul code*/'<li><a class="category-links" href="' zen_href_link(FILENAME_PRODUCTS_ALL) . '">' CATEGORIES_BOX_HEADING_PRODUCTS_ALL '</a>' /*ul code*/'</li>' "\n";
        }
        
    $content .= /*ul code*/'</ul>';
      }
      
    $content .= '</div>';
    ?>
    As a bonus, it also contains the line (commented out) to limit Expanded Category List display to just top and first level subcats.

    Some adapting work will be needed to integrate this with your expanded/products version of the file.
    Last edited by gjh42; 21 Dec 2007 at 10:28 PM.

  5. #5
    Join Date
    Apr 2006
    Location
    Dark Side of the Moon
    Posts
    987
    Plugin Contributions
    1

    Default Re: Help nesting products under categories in side bar

    Glenn,

    May I make one suggestion to your code so IE 6 (and maybe earlier) works "better"?

    File: tpl_categories.php

    line 73: $content .= '</li'. "\n".'>' ;/*ul code*/

    This fixes the big gaps you get in IE that other browsers handle correctly.

    This in effect makes the unordered list appear to be one line.

    -Chadd

  6. #6
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Help nesting products under categories in side bar

    Thanks for that. Since I only use IE when I have to, I didn't even realize there was a problem there. I'll check it out.

    I have made some improvements to the code, and when I settle on the best methods I'll repost the file. I don't think it warrants a mod in Downloads. I have code for it that would allow switching between ul display and the stock display with one constant or variable change, but not sure there is enough benefit to that to warrant the extra complexity. I'll probably streamline it for just ul display.

  7. #7
    Join Date
    Apr 2006
    Location
    Dark Side of the Moon
    Posts
    987
    Plugin Contributions
    1

    Default Re: Help nesting products under categories in side bar

    Glenn,

    Yep, I rarely use IE so I often forget to check it!

    A couple of notes... check out this site for some interesting CSS design layouts:

    http://webhost.bridgew.edu/etribou/layouts/

    And a sample of his code in use:

    http://chicagophoto.net/sandra/

    Also, have you compared performance of <UL> vs <SPAN>?? I tried your code last night because I am trying to fix a IE bug in my categories and it seemed the the <UL> version was a bit slower on load. I hadn't come across this before, but then I didn't have a categories list this large:

    http://chicagophoto.net/zen138/

    I am having problems with IE not displaying the top two <li> or <spans> correctly. I've spent hours on it already! I know it has to be a IE box model problem but it evades me.

    I want to style the listing so it has a nice button look, but don't know why this is happening.

 

 

Similar Threads

  1. v150 Nav Bar under header is too narrow for two rows of Categories
    By CultureClick in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 10 Jun 2012, 06:13 AM
  2. Additional Categories Headings in left Side Bar
    By Yolanda in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 28 Nov 2011, 11:25 PM
  3. sub categories in left side bar
    By b-summers in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 19 Aug 2009, 01:33 AM
  4. How to Add SSL Seal to Side Bar Under Side Boxes
    By jacdesigner in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 20 Mar 2009, 08:54 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg