Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Display Subcategories of Parent, While in Subcategory

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 06-28-2011, 10:09 AM
 
nickff nickff is offline
 

Senior Member
  
Join Date: Aug 2010
Posts: 132
 

Default 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!
__________________
nick hoag
looking forward to the future
http://thefutureforward.com
xcart versions 4.2.x, 4.3.x, 4.4.x
Reply With Quote
  #2  
Old 06-28-2011, 10:44 AM
 
nickff nickff is offline
 

Senior Member
  
Join Date: Aug 2010
Posts: 132
 

Default 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!
__________________
nick hoag
looking forward to the future
http://thefutureforward.com
xcart versions 4.2.x, 4.3.x, 4.4.x
Reply With Quote
  #3  
Old 06-28-2011, 11:53 AM
  ARW VISIONS's Avatar 
ARW VISIONS ARW VISIONS is offline
 

X-Man
  
Join Date: Jan 2007
Location: Pensacola, FL
Posts: 2,536
 

Default Re: Display Subcategories of Parent, While in Subcategory

shouldn't you put the PHP in php file?
__________________
xcart 5.1.2
Reply With Quote
  #4  
Old 06-28-2011, 12:00 PM
 
nickff nickff is offline
 

Senior Member
  
Join Date: Aug 2010
Posts: 132
 

Default Re: Display Subcategories of Parent, While in Subcategory

Probably, but with a deadline looming, this worked so I ran with it!
__________________
nick hoag
looking forward to the future
http://thefutureforward.com
xcart versions 4.2.x, 4.3.x, 4.4.x
Reply With Quote
  #5  
Old 06-28-2011, 12:42 PM
  cherie's Avatar 
cherie cherie is offline
 

X-Wizard
  
Join Date: May 2003
Location: USA
Posts: 1,534
 

Default 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.
__________________
redlimeweb.com
custom mods and design integration
4.7 linux
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:32 PM.

   

 
X-Cart forums © 2001-2020