Results 1 to 10 of 14

Hybrid View

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

    Default Help nesting products under categories in side bar

    Hello, I've been trying to nest the products below categories on the sidebar with UL tags. It appears to continue to add UL tags to each product vs having it add the UL tags before and after all the products to nest them under the cat, and it's not what I want... Here is a snapshot of how it looks like. Notice how it says BEGINEND. I'm using BEGIN as an example for UL and END as an example for /UL

    I need BEGIN and END to nest for example, the two red items in the list so it would be a sub-list basically. I am terrible at php, so I tried my best.




    PHP Code:
    <?php

      $content 
    "";
        
    $content .= '<ul>' "\n";

      for (
    $i=0;$i<sizeof($box_categories_array);$i++) {
         
         
    //set selected style ($box_categories_array[$i]['current'] does not work)    
        
         
    $div_class='';
         if (
    $products_id){
         
             if ((
    $products_id)&&($box_categories_array[$i]['products_id']==$products_id)){
                 
    $div_class='category-subs-selected';
             }
         }else{
             if((
    $current_category_id!=0)&&($box_categories_array[$i]['category_id']==$current_category_id)){
                 
    $div_class='category-subs-selected';
             }
         }              
        
        
    // set top style
        
    if ($box_categories_array[$i]['top'] == 'true'){    
            
    $a_class 'category-top';
        }elseif(
    $box_categories_array[$i]['has_sub_cat']){
            
    $a_class 'category-subs';
        }else{
            
    $a_class='category-products';
        }
         
    // link to cat or prod
        
    if ($box_categories_array[$i]['is_product'] == true){
            
    $link zen_href_link(FILENAME_PRODUCT_INFO$box_categories_array[$i]['path']);
        }else{
            
    $link zen_href_link(FILENAME_DEFAULT$box_categories_array[$i]['path']);
        }    
        
        




        
        if(
    $box_categories_array[$i]['is_product'] == true){
            
    $content .= "BEGIN";
        }
        
        
        
    //indent
        
    if($box_categories_array[$i]['is_product'] == true){
            
    $indent str_repeat($box_categories_array[$i]['level']+1); 
        }else{
            
    $indent str_repeat($box_categories_array[$i]['level']); 
        }
        
        
        
        if(
    $box_categories_array[$i]['is_product'] == true){
            
    $content .= "END";
        }
        





        
        
    //cat sub seperator
        
    if (($box_categories_array[$i]['level'] == 0)&&($box_categories_array[$i]['is_product'] == false)){
            
    $separator '';
        }else{
        }
        
    // count
        
    $count='';
        if (
    SHOW_COUNTS == 'true') {
            if(
    $box_categories_array[$i]['is_product'] != true){
                
    $count CATEGORIES_COUNT_PREFIX $box_categories_array[$i]['count'] . CATEGORIES_COUNT_SUFFIX ;
            }
        }
        
    //add content
        
        
    $content .= '<li>'
        
    $indent.$separator.'<a class="'$a_class .'" href="'$link .'">'$box_categories_array[$i]['name'] . '</a>';
        
    $content .= '</li>';
        
        
        
      }

      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";
        }
        
        if (
    SHOW_CATEGORIES_BOX_SPECIALS == 'true') {
        
    $content .= "BEGIN EXTRA LINKS";
          
    $show_this $db->Execute("select s.products_id from " TABLE_SPECIALS " s where s.status= '1' limit 1");
          if (
    $show_this->RecordCount() > 0) {
            
    $content .= '<a class="category-links" href="' zen_href_link(FILENAME_SPECIALS) . '">' CATEGORIES_BOX_HEADING_SPECIALS '</a>' '<br />';
          }
        }
        
        if (
    SHOW_CATEGORIES_BOX_PRODUCTS_NEW == 'true') {
          switch (
    true) {
            case (
    SHOW_NEW_PRODUCTS_LIMIT == '0'):
              
    $display_limit '';
              break;
            case (
    SHOW_NEW_PRODUCTS_LIMIT == '1'):
              
    $display_limit " and date_format(p.products_date_added, '%Y%m') >= date_format(now(), '%Y%m')";
              break;
            case (
    SHOW_NEW_PRODUCTS_LIMIT == '30'):
              
    $display_limit ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 30';
              break;
            case (
    SHOW_NEW_PRODUCTS_LIMIT == '60'):
              
    $display_limit ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 60';
              break;
            case (
    SHOW_NEW_PRODUCTS_LIMIT == '90'):
              
    $display_limit ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 90';
              break;
            case (
    SHOW_NEW_PRODUCTS_LIMIT == '120'):
              
    $display_limit ' and TO_DAYS(NOW()) - TO_DAYS(p.products_date_added) <= 120';
              break;
          }

          
    $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 .= '<a class="category-links" href="' zen_href_link(FILENAME_PRODUCTS_NEW) . '">' CATEGORIES_BOX_HEADING_WHATS_NEW '</a>' '<br />';
          }
        }
        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 .= '<a class="category-links" href="' zen_href_link(FILENAME_FEATURED_PRODUCTS) . '">' CATEGORIES_BOX_HEADING_FEATURED_PRODUCTS '</a>' '<br />';
          }
        }
        if (
    SHOW_CATEGORIES_BOX_PRODUCTS_ALL == 'true') {
          
    $content .= '<a class="category-links" href="' zen_href_link(FILENAME_PRODUCTS_ALL) . '">' CATEGORIES_BOX_HEADING_PRODUCTS_ALL '</a>';
        }
      }
        
    $content .= '</ul>';

    ?>

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

    Default Re: Help nesting products under categories in side bar

    You already have <ul> tags where they belong, just before and after the for loop. Where you have BEGIN and END, you want to put '<li>' and '</li>' to make each product a list item (not a new list).

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

    Default Re: Help nesting products under categories in side bar

    The products already have <li></li>

    I want to make sure they are nested with <ul></ul> tags. So in essence it looks like this:

    HTML Code:
    <ul>
    <li>Product Category 1</li>
    <li>Product Category 2
    
    <ul>
    <li>Product 1</li>
    <li>Product 2</li>
    <li>Product 3</li>
    </ul>
    
    </li>
    
    <li>Product Category 3</li>
    <li>Product Category 4</li>
    
    </ul>
    Nested.

  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

    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.

  5. #5
    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.

  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

    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.

 

 

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