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)
-   -   subcategory list on home (https://forum.x-cart.com/showthread.php?t=7074)

luoifong 04-09-2004 09:01 AM

subcategory list on home
 
I would like to list different subcategory groups on the home page. I know customer/categories.tpl lists the top level categories. customer/main/subcategories.tpl displays a particular subcategory, but that is coming from a page (the home page for example) that sends along a category id.

So on the home page (which hasn't received a particular category id, and I would want numerous subcategory group listings anyway) I'm not sure how to list different subcategory groups.

Anyone know how to do this...or do I have to hard code in the subcategory links into the home page?

Thanks!

mcopeland 04-20-2004 01:41 AM

Hi,

Have you ever figured this out? Did you progress on the matter?

Please advise.

Thanks.

joshf 04-20-2004 08:25 AM

Quote:

Originally Posted by mcopeland
Have you ever figured this out? Did you progress on the matter?


Hey Melcom,

Coincidence that we both happened across this topic on the same day. I'm also looking for a solution to this...

If anyone has any ideas, please post it here!

2getInk 04-20-2004 10:10 AM

Hey guys,
I am also looking for the same solution.
Take a look at categories of http://www.savatrader.com/shop/customer/home.php.
If this is possible, then the solution we are looking for should be simple.
I will search through the forum and let everyone know if I find something useful.
Thanks.

2getInk 04-20-2004 10:52 AM

Hi,
I have found a code by boomer which was for the kind of thing done on http://www.savatrader.com/shop/customer/home.php.
I have modified the code to make it suitable for us.
Hope it helps everyone.


I have tested it on x-cart version: 3.4.12

Edit skin1/customer/categories.tpl:

Code:

{section name=cat_num loop=$categories}

{$categories[cat_num].category_name}
<span class="sub" id="{$categories[cat_num].categoryid}">
{section name=subcat_num loop=$categories_data}
{if $categories_data[subcat_num].root_category_name == $categories[cat_num].category && $categories_data[subcat_num].category_name != $categories[cat_num].category_name}   
<a href="home.php?cat={$categories_data[subcat_num].categoryid}">
-{$categories_data[subcat_num].category_name}</A>
{/if}
{/section}
</span>
{/section}




Edit include/categories.php:

Comment out the line (just add a # in front of it):

Code:

$categories_data = func_query("select $sql_tbl[categories].*, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -1) as category_name from $sql_tbl[categories] ".($current_area=="C"?"where $sql_tbl[categories].avail='Y' $membership_condition ":"")." group by $sql_tbl[categories].categoryid order by ".($current_area=="C" ? "order_by" : "category"));


and add the following underneath it:

Code:

$categories_data = func_query("select $sql_tbl[categories].*, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -1) as category_name, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', 1) as root_category_name from $sql_tbl[categories] ".($current_area=="C"?"where $sql_tbl[categories].avail='Y' $membership_condition ":"")." group by $sql_tbl[categories].categoryid order by ".($current_area=="C" ? "order_by" : "category"));


Then go down to the bottom of the file where the "Assign Smarty variables" comment is, underneath it add:

Code:

$smarty->assign("categories_data",$categories_data);


joshf 04-20-2004 12:15 PM

Works over here.... Thanks for the post.

luoifong 04-20-2004 09:28 PM

I had finally gone the route of hard coding the links...I'll try out this code.

Thanks for the post 2getInk!

2getInk 04-29-2004 01:37 AM

Glad to help. :wink:

carlisleglass 05-05-2004 06:30 AM

HELP !!!

This coding works a treat but it displays all sub categories within a main categories ... how do i change the coding so it only shows the first level sub categories. I know it has something to do with checking to see if the categories name has a second / in it, but dont know php that way to sort it

B00MER 05-05-2004 07:42 AM

Code:

$categories_data = func_query("select $sql_tbl[categories].*, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -1) as category_name, SUBSTRING_INDEX($sql_tbl[categories].category, '\/', 1) as root_category_name, SUBSTRING_INDEX(SUBSTRING_INDEX($sql_tbl[categories].category, '\/', -2),'\/',1) as sub_category_name from $sql_tbl[categories] ".($current_area=="C"?"where $sql_tbl[categories].avail='Y' $membership_condition ":"")." group by $sql_tbl[categories].categoryid order by ".($current_area=="C" ? "order_by" : "category"));

This will get the sub_category_name as well. :wink:

template code for the 1st tier from root:

Code:

{if $categories_data[subcat_num].root_category_name == $categories_data[cat_num].category && $categories_data[subcat_num].category_name != $categories_data[cat_num].category_name && $categories_data[subcat_num].sub_category_name == $categories_data[subcat_num].root_category_name}


All times are GMT -8. The time now is 12:16 AM.

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