X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Display Subcategories of Parent, While in Subcategory (https://forum.x-cart.com/showthread.php?t=59974)

nickff 06-28-2011 10:09 AM

Display Subcategories of Parent, While in Subcategory
 
Hi All,

I've made a dropdown menu at the top of my category pages in a 4.4.3 store that lists the subcategories in that category, like so:

HTML Code:


<select class="gender-select" onchange="if(this.options[this.selectedIndex].value != '')window.top.location.href=this.options[this.selectedIndex].value">

        <option value="Select A Gender">mens/womens/youth</option>
        {foreach from=$categories item=subcat name=subcategories}
            <option value="home.php?cat={$subcat.categoryid}">{$subcat.category|escape}</option>
        {/foreach}

</select>


I would like this dropdown menu to be visible and function even after you go into a subcategory. Currently, it shows on the parent category page correctly, but then when you go into a subcategory the selections are no longer in the menu.

http://future.thefutureforward.com/~aso/Snow/

I think I need an if statement in there that grabs the parent's subcats when in a subcat, but I'm not sure how to do it.

Any help is much appreciated!

nickff 06-28-2011 10:44 AM

Re: Display Subcategories of Parent, While in Subcategory
 
SOLVED thanks to this post - http://forum.x-cart.com/showthread.php?p=320214#post320214

Here's how I did it:

In subcategories.tpl:
HTML Code:

{include file="customer/main/subcategories_dropdown.tpl"}

In subcategories_dropdown.tpl:
HTML Code:


{php}
        $t = $this->get_template_vars('cat');
       
        $result=mysql_query("select * from xcart_categories where categoryid=$t");
        while($row=mysql_fetch_array($result))
        {
            $cid=$row['categoryid'];
            $pid=$row['parentid'];
            $cat=$row['category'];
        }
    {/php}
    <select name="mySelect" class="gender-select"  onchange="if(this.options[this.selectedIndex].value !=  '')window.top.location.href=this.options[this.selectedIndex].value">
        <option value="Select A Gender">mens/womens/youth</option>
        {php}
           
            if($pid==0){
            $res=mysql_query("select * from xcart_categories where parentid=$t");
            while($row1=mysql_fetch_array($res))
            {
            $cat12=$row1['category'];
            $cid12=$row1['categoryid'];
           
        {/php}
        <option value="home.php?cat={php}echo $cid12; {/php}">{php}echo $cat12;{/php}</option>
        {php}
            }
            }else {
            $res=mysql_query("select * from xcart_categories where parentid=$pid");
            while($row1=mysql_fetch_array($res))
            {
            $cat12=$row1['category'];
            $cid12=$row1['categoryid'];
        {/php}
        <option value="home.php?cat={php}echo $cid12; {/php}">{php}echo $cat12;{/php}</option>
        {php}
            }
           
            }
        {/php}
    </select>


Works perfectly!

ARW VISIONS 06-28-2011 11:53 AM

Re: Display Subcategories of Parent, While in Subcategory
 
shouldn't you put the PHP in php file?

nickff 06-28-2011 12:00 PM

Re: Display Subcategories of Parent, While in Subcategory
 
Probably, but with a deadline looming, this worked so I ran with it!

cherie 06-28-2011 12:42 PM

Re: Display Subcategories of Parent, While in Subcategory
 
Nice solution!

{php} is deprecated so you'll definitely want to clean this up when you have a chance. Maybe post your new solution then. :)


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

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