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

ALWAYS display first level subcats beneath root cats

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #51  
Old 06-15-2007, 06:40 AM
 
Surface 51 Surface 51 is offline
 

Newbie
  
Join Date: May 2007
Posts: 3
 

Default Re: ALWAYS display first level subcats beneath root cats

@BornMunson

I'm having the exact same issue. It only shows the sub categories when I'm on the parent category page. And I am using 4.1.7, maybe that's the problem?

Edit: Fixed it. Here's what I did (but the css is different)

{capture name=menu}
{if $active_modules.Fancy_Categories ne ""}
{include file="modules/Fancy_Categories/categories.tpl"}
{assign var="fc_cellpadding" value="0"}
{else}
{if $config.General.root_categories eq "Y"}
<ul id="mainmenu">
{foreach from=$categories item=c}
{if $cat eq $c.categoryid || $current_category.parentid eq $c.categoryid}
<li><a href="home.php?cat={$c.categoryid}">{$c.category}< /a></li>
{else}
<li><a href="home.php?cat={$c.categoryid}">{$c.category}< /a></li>
{/if}
{assign var=in value=$c.categoryid}
{* CONDITIONAL DROP DOWN ITEMS FROM TOP CATEGORY *}
<ul id="submenu">
{foreach from=$allsubcategories.$in item=c }
{if $cat eq $c.categoryid}
<li><a href="home.php?cat={$c.categoryid}">{$c.category}< /a></li>
{else}
<li><a href="home.php?cat={$c.categoryid}">{$c.category}< /a></li>
{/if}
{/foreach}
</ul>
{* /CONDITIONAL *}
{/foreach}
{else}
{foreach from=$subcategories item=c key=catid}
<li><a href="home.php?cat={$catid}">{$c.category}</a></li>
{/foreach}
{/if}
</ul>
{/if}
__________________
4.1.8
Reply With Quote
  #52  
Old 06-15-2007, 09:31 PM
 
BornMunson BornMunson is offline
 

Advanced Member
  
Join Date: Jan 2005
Posts: 46
 

Default Re: ALWAYS display first level subcats beneath root cats

Thanks Surface51. That worked perfectly!!
__________________
X-Cart 4.7.3
Reply With Quote
  #53  
Old 07-17-2007, 02:45 AM
 
membot membot is offline
 

Advanced Member
  
Join Date: Jan 2007
Posts: 55
 

Default Re: ALWAYS display first level subcats beneath root cats

Quote:
Originally Posted by chris2002
Solution for 4.1.6

like this

CAT A
--CAT A1
--CAT A2
CAT B
--CAT B1
--CAT B2

in incude/categorie.php

Search for this in your code :
#
# Override subcategory_count for Admin area
#
if(!empty($subcategories) && ($current_area == 'A' || ($current_area == 'P' && $active_modules['Simple_Mode']))) {
$product_counts = func_query_hash("SELECT categoryid, COUNT(*) FROM $sql_tbl[products_categories] WHERE categoryid IN ('".implode("','", array_keys($subcategories))."') GROUP BY categoryid", "categoryid", false, true);
foreach($subcategories as $k => $v) {
$subcategories[$k]['subcategory_count'] = func_query_first_cell("SELECT COUNT(subcat.categoryid) as subc FROM $sql_tbl[categories] USE INDEX (PRIMARY) LEFT JOIN $sql_tbl[categories] as subcat ON subcat.categoryid_path LIKE CONCAT($sql_tbl[categories].categoryid_path, '/%') WHERE $sql_tbl[categories].categoryid = '$k' GROUP BY $sql_tbl[categories].categoryid");
$subcategories[$k]['product_count_global'] = $subcategories[$k]['product_count'];
$subcategories[$k]['product_count'] = isset($product_counts[$k]) ? intval($product_counts[$k]) : 0;
}
}



then add this just below the line :


//Subcategories in menu
function func_getallsubcat()
{
$raj =func_get_categories_list("", true, "all");
$raj1=$raj['all_categories'];
$ll=array();
foreach ($raj1 as $k=>$val)
{
if($val['parentid']!="0")
{
$ll[$val['parentid']][]=$val;
}
}
return $ll;
}
$smarty->assign("allsubcategories", func_getallsubcat());
//Subcategorie in menu - end


and in skin1/customer/categories.tpl

Where you need to show the subcategorie
{assign var=in value=$c.categoryid}
{foreach from=$allsubcategories.$in item=c }

and the link to show subcategories
<a href="home.php?cat={$c.categoryid}" class="yourclassforsub">{$c.category}<br></a>

thank you I was forogotten it in my previous post

Thank you

You absolutely rock Chris! I had absolutely no idea how to do this. I may post another version I'm working of this if I ever get my bits to work. Thanks again!
__________________
X-Cart Version 4.1.10
www.memedia.com.au
Reply With Quote
  #54  
Old 07-17-2007, 02:24 PM
 
pyrotec pyrotec is offline
 

Advanced Member
  
Join Date: Jan 2007
Posts: 31
 

Default Re: ALWAYS display first level subcats beneath root cats

just wondering, what *.tpl file does this code go in? and will it work with 4.1.8?
__________________
x-cart gold
ver 4.1.8
Reply With Quote
  #55  
Old 07-23-2007, 04:10 AM
 
membot membot is offline
 

Advanced Member
  
Join Date: Jan 2007
Posts: 55
 

Default Re: ALWAYS display first level subcats beneath root cats

Quote:
Originally Posted by pyrotec
just wondering, what *.tpl file does this code go in? and will it work with 4.1.8?

You can pretty much put the code for the .tpl file into any .tpl file and display it anywhere you like on your site. It most certainly does work on 4.1.8 as is.
__________________
X-Cart Version 4.1.10
www.memedia.com.au
Reply With Quote
  #56  
Old 07-23-2007, 04:22 AM
 
membot membot is offline
 

Advanced Member
  
Join Date: Jan 2007
Posts: 55
 

Default Re: ALWAYS display first level subcats beneath root cats

Help Please!

I'm trying to display a description beside each of the subcategories. and this is my first attempt at smarty. Somehow I managed to fumble my way forward and did get the descriptions to appear using another smarty variable / array (not sure of terminology sorry). Anyway.. here is my code. If anybody could maybe tell me where I'm going wrong I'd really appreciate it! Once I get it all working I'll post all code.

PHP Code:
//Subcategories in menu 
function func_getallsubcat()
{
$raj =func_get_categories_list(""true"all");
$raj1=$raj['all_categories'];
$ll=array();
foreach (
$raj1 as $k=>$val)
{
if(
$val['parentid']!="0")
{
$ll[$val['parentid']][]=$val;
}
}
return 
$ll
}
$smarty->assign("allsubcategories"func_getallsubcat()); 
function 
func_getsubdesc()
{
$allsubcategories func_getallsubcat();
$subcatdescriptions = array();
foreach(
$allsubcategories as $k => $v)
{
$subcatdescriptions[$k] = func_query("SELECT * from xcart_categories, xcart_images_C where xcart_categories.categoryid = '$k' AND xcart_images_C.id = xcart_categories.categoryid "); 
}
return 
$subcatdescriptions;
}
$smarty->assign("subcatdescriptions"func_getsubdesc());
//Subcategorie in menu - end 

To Clarrify... I got most of the subcategory descriptions to display + images using the following code but could not get all of them to display the description and image. But all subcategory names most certainly did appear.

PHP Code:
<table width="100%" cellpadding="5" cellspacing="1"
{
assign var="cat_per_row" value=2}
{
assign var="cell_counter" value=0}
{
math equation="floor(100/x)" x="$cat_per_rowassign="width"}
{
math equation="x-1" x="$cat_per_rowassign="end_row"}
{if 
$config.General.root_categories eq "Y"}
{foreach 
from=$categories item=c}
 
{if 
$c.icon_url
{
math equation="x+1" x=$cell_counter assign="cell_counter" 
{if 
$cell_counter lt $cat_per_row }
<
tr>
{/if}
<
td width="{$width}%" valign="top">
<
a href="home.php?cat={$c.categoryid}"><img src="{$c.icon_url}alt="{$c.category}/></a><br /><br /> 
<
table width="100%">
{
assign var=in value=$c.categoryid}
{
assign var="subcat_counter" value=0}
{foreach 
from=$allsubcategories.$in item=}
{
math equation="x+1" x=$subcat_counter assign="subcat_counter" }
{if 
$subcat_counter 6}
{if 
$cat eq $c.categoryid}
<
tr>
<
td width="75"><a href="home.php?cat={$c.categoryid}"><img src="{$subcatdescriptions[$c.categoryid][0].icon_url}alt="{$c.category}></a></td>
<
td class="SubCategoryDesc">
<
a href="home.php?cat={$c.categoryid}class="SubCategoryBoldMenu">{$c.category}<a><br />
{
$subcatdescriptions[$c.categoryid][0].description|truncate:80:"...":true}</td>
</
tr>
{else}
<
tr>
<
td width="75">{if $subcatdescriptions[$c.categoryid][0].image_path}<a href="home.php?cat={$c.categoryid}"><img src="{$subcatdescriptions[$c.categoryid][0].image_path}alt="{$c.category}></a>{/if}</td>
<
td class="SubCategoryDesc" width="219">
<
a href="home.php?cat={$c.categoryid}class="SubCategoryBoldMenu">{$c.category}</a><br />
{
$subcatdescriptions[$c.categoryid][0].description|truncate:80:"...":true}</td>
</
tr>
{/if}
{else}
{if 
$subcat_counter eq 6}
</
table>
<
table width="100%">
{/if}
{if 
$subcat_counter is div by $cat_per_row}
<
tr
{/if}
{if 
$cat eq $c.categoryid}
<
td height"18"><a href="home.php?cat={$c.categoryid}class="SubCategoryBoldMenuItems">{$c.category}<a></td>
{else}
<
td height"18"><a href="home.php?cat={$c.categoryid}class="SubCategoryBoldMenuItems">{$c.category}<a></td>
{/if}
{if 
$subcat_counter is not div by $cat_per_row}
</
tr
{/if}
{/if} 
{/foreach}
</
table>
</
td>
{if 
$cell_counter eq $cat_per_row}
</
tr>
{
assign var="cell_counter" value=0}
{/if}
{/if}
{/foreach}
{else} {foreach 
from=$subcategories item=c key=catid}
<
a href="home.php?cat={$catid}">{$c.category}</a
{/foreach}
{/if}
</
table

I've also included a screen shot. U can see the main category images then subcats with descriptions listed for the first "Root Categories" but it doesn't seem to work for the next "Root Categories" being the "Compression and Specials" seen below.
http://www.memedia.com.au/subcats.jpg

please help
__________________
X-Cart Version 4.1.10
www.memedia.com.au
Reply With Quote
  #57  
Old 09-17-2007, 10:36 PM
 
Kevin2 Kevin2 is offline
 

Newbie
  
Join Date: Aug 2007
Posts: 5
 

Default Re: ALWAYS display first level subcats beneath root cats

Hi surface51 thank you for your input. I added it and I now have subcats but at the end of each one I have </a>

How do I get rid of the </a>?

Many thanks
Kevin
__________________
xcart gold 4.1.7
Reply With Quote
  #58  
Old 09-18-2007, 12:32 AM
 
Kevin2 Kevin2 is offline
 

Newbie
  
Join Date: Aug 2007
Posts: 5
 

Default Re: ALWAYS display first level subcats beneath root cats

Ok sorted it out
__________________
xcart gold 4.1.7
Reply With Quote
  #59  
Old 11-21-2007, 01:25 PM
 
webstar webstar is offline
 

Newbie
  
Join Date: Oct 2004
Posts: 8
 

Default Re: ALWAYS display first level subcats beneath root cats

Just wanted to say thank you to all who contributed to this thread. It really helped me out a bunch.

Thank you!
__________________
X-Cart 4.0.19 Gold on Linux
Reply With Quote
  #60  
Old 12-10-2007, 02:37 AM
 
TanyaG TanyaG is offline
 

Advanced Member
  
Join Date: Nov 2007
Posts: 94
 

Default Re: ALWAYS display first level subcats beneath root cats

Quote:
Originally Posted by Jeremy.Freeman
Fixed it.. you need to comment out the following line in include/categories.php to sort the subcategories by pos:

usort($all_categories, "func_categories_sort");

I should appear around line 165ish

Hi, unfortunately can’t make it work. Could you let me know what you changed in categories.php to fix it?

Thanks a lot.
__________________
Tanya

x-cart version: 4.1.7 4.1.9. 4.2
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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 03:08 PM.

   

 
X-Cart forums © 2001-2020