X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Categories Menu - Showing Subcategories (https://forum.x-cart.com/showthread.php?t=3242)

inVINCEible 06-18-2003 11:23 AM

Categories Menu - Showing Subcategories
 
What would I need to do to get the subcategories to show for the category that the user is currently in?

For example, on the main page, the category menu would show:

- Cat A
- Cat B
- Cat C
- Cat D

However, if you click on Cat A, or go to a product that is in Cat A, the menu would show:

- Cat A
--- Sub Cat 1
--- Sub Cat 2
--- Sub Cat 3
- Cat B
- Cat C
- Cat D

Any help would be greatly appreciated. Thanks!

inVINCEible 06-18-2003 11:47 AM

So far.. I have..

Code:

{if $config.General.root_categories eq "Y"}
{section name=cat_num loop=$categories}
{ $categories[cat_num].category|escape }
      {if $cat eq $categories[cat_num].categoryid}
      {section name=subcat_num loop=$subcategories}
      { $subcategories[cat_num].category|escape }
      {/section}
      {/if}
{/section}
{/if}


..but it's outputting the same subcategory.

So for Cat A, instead of getting:

- Cat A
--- Sub Cat 1
--- Sub Cat 2
--- Sub Cat 3
- Cat B
- Cat C
- Cat D

...i get

- Cat A
--- Sub Cat 1
--- Sub Cat 1
--- Sub Cat 1
- Cat B
- Cat C
- Cat D

brgreene 06-19-2003 11:43 AM

I would like to display my menus this way also. Did you ever figure it out.

kpayne 06-19-2003 12:28 PM

Try this:

Code:

{section name=cat_num loop=$categories}
{ $categories[cat_num].category|escape }

      {if $cat eq $categories[cat_num].categoryid}
      {section name=subcat_num loop=$subcategories}
        { $subcategories[subcat_num].category|escape }

      {/section}
      {/if}
{/section}


You didn't have the index in the inner loop set correctly (cat_num vs. subcat_num). I also added "
" tags to make it display properly.

Hope this helps!

--Kurt

inVINCEible 06-19-2003 01:39 PM

thanks! it works like a charm. :) I didnt have the
in there because the code sniplet i posted was a stripped down version of what im using... i have my menu setup in tables.

http://www.aheadgames.com/cart/customer/home.php

Here's the /customer/categories.tpl I'm using if anyone wants to do anything similar.. you might have to change things a bit to work with your cart. :)
Code:

        <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="250">
{if $config.General.root_categories eq "Y"}
{section name=cat_num loop=$categories}
          <tr>
            <td height="20" background="../../images/categorybg.gif">
            <p align="left" class="menutext">{ $categories[cat_num].category|escape }</td>
          </tr>
{if $cat eq $categories[cat_num].categoryid}
{section name=subcat_num loop=$subcategories}
          <tr>
            <td height="20" background="../../images/categorybg.gif" class="menutext">{ $subcategories[subcat_num].category|escape }</td>
          </tr>
{/section}
{/if}
{/section}
{/if}
          <tr>
            <td height="20" background="../../images/categorybg.gif" class="menutext">{$lng.lbl_gift_certificates}</td>
          </tr>
          <tr>
            <td background="../../images/categorybgshadow.gif" height="18">
            <font face="Arial" size="1"></font></td>
          </tr>
        </table>


shan 06-19-2003 01:51 PM

Nice mod that, moved to custom templates 8)

brgreene 06-22-2003 01:04 PM

inVINCEible,

How did you get the sub-categories to stay after a person clicks them. Did you have to make any other modifications?

The categories and sub-categories are displaying correctly but if you click a sub-Categorie only the main categories are showing. The Sub-Categories disappear.




Code:

<TABLE border=0 cellPadding=2 cellSpacing=0 width=100%>
  <tr>
    <td colspan="2" align="center" class="VertMenuTitle">[img]{$ImagesDir}/category.gif[/img]</td>
  </tr>
  {if $config.General.root_categories eq "Y"}
  {section name=cat_num loop=$categories}
  <tr>
    <td height="15" valign="middle" class="VertMenuBox">
      <p align="left"><a href="home.php?cat={ $categories[cat_num].categoryid }"> {
        $categories[cat_num].category|escape }</a></td>
  </tr>
  {if $cat eq $categories[cat_num].categoryid} {section name=subcat_num loop=$subcategories}
  <tr>
    <td height="15" valign="middle" class="VertSubMenuBox">-<a href="home.php?cat={ $subcategories[subcat_num].categoryid }">{
      $subcategories[subcat_num].category|escape }</a></td>
  </tr>
  {/section}
  {/if}
  {/section}
  {/if}
</table>


blagarde 06-24-2003 07:02 AM

This is extremely cool and almost exactly what I am in need of right now! But Brian has a really good question. Additionally, I'd like to figure out a way to have the first main category initially opened by default, showing its sub-categories when a person first goes to the site. That way it will be more obvious to less experienced users that all these menus open to reveal more.

ajaycg 06-25-2003 08:09 AM

:)

Hey inVINCEible,

Ditto to the two above, fantastic mod.. must admit, the ahead games site looks awesome..

Got a question... same as Brian... How did you get the sub-categories to stay after a person clicks them. would love to know how you did it!

Cheers man..

Aj

barabbas 06-28-2003 03:58 PM

http://www.below-0.net

is there any chance you can make it more like that? by this i mean, not open up a new page aswell as revieling the lst of subcats


All times are GMT -8. The time now is 06:48 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.