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)
-   -   Mod for subcategories in columns with descriptions and icons (https://forum.x-cart.com/showthread.php?t=3848)

scottWB 06-29-2006 01:59 AM

This works for me to get multiple row categories with icons in 4.1.1. My use doesn't need text or descriptions, so you'll have to add that back if you do. Still needs some cleaning up, but it works. This is just a snip from the template.

Code:

{if $subcategories}


<table border="0" cellspacing="5" width="100%">
<tr>
{foreach from=$subcategories item=subcat}



  {if $tmp is not div by 2}
    </tr><tr valign="top">
  {/if}

<td class="SubcatTitle"><a href="home.php?cat={ $subcat.categoryid }" title="{ $subcat.category }">
[img]image.php?id={$subcat.categoryid}&amp;type=C[/img]
</a></td>

{assign var="tmp" value=$tmp+1}

{/foreach}
</tr></table>

{/if}


mffowler 06-29-2006 04:02 PM

Close, but use the file system for the cat. images. The code needs to be reworked using sections to allow for multiple columns (am trying it now), but here's your previous code with names and content and using the file system. I have left your database image call to see what was coded out...
Code:

{if $subcategories}
<table border="0" cellspacing="5" width="100%">
<tr>
{foreach from=$subcategories item=subcat}
  {if $tmp is not div by 2}
    </tr><tr valign="top">
  {/if}
<td class="SubcatTitle"><a href="home.php?cat={ $subcat.categoryid }" title="{ $subcat.category }">{if $subcat.icon_url}[img]{$subcat.icon_url}[/img]{else}[img]{$xcart_web_dir}/default_icon.gif[/img]{/if}

{*
[img]image.php?id={$subcat.categoryid}&amp;type=C[/img]
*}

</a>



<font class="ItemsList">{ $subcat.category|escape }</font>


{if $config.Appearance.count_products eq "Y"}
{if $subcat.product_count}{ $subcat.product_count } {$lng.lbl_products}
{elseif $subcat.subcategory_count}{ $subcat.subcategory_count } {$lng.lbl_categories|lower}
{/if}
        {/if}

</td>
{assign var="tmp" value=$tmp+1}
{/foreach}
</tr></table>
{/if}

- Mike

MCM 06-29-2006 08:50 PM

This is a great mod! I've got an idea for an addition and two questions:

First, I've made the Icon/Category one link, instead of two on top of each other... no big deal. I've also added a title tag to the link, though, so when someone hovers, there can be text... this seems like it should be good for adding keyword density to the link. The problem is, I can't find the smarty tag for the category description, which is, in my opinion, highly appropriate for the title tag. If you can tell me the tag, I'd be very grateful.

Second, when a category has no products, there is nothing beneath the Category name. Is there a way for it to say "0 Items" instead of it being blank?

Here's my subcategories.tpl:

Code:

{* $Id: subcategories.tpl,v 1.43.2.2 2004/10/07 07:08:51 max Exp $ *}
{if $active_modules.Bestsellers ne "" and $config.Modules.bestsellers_menu ne "Y"}



{include file="modules/Bestsellers/bestsellers.tpl"}
{/if}



{if ($navigation_page eq "")||($navigation_page eq "1")}{$current_category.description|regex_replace:"/[\n]/":"
"}

{/if}
{capture name=dialog}
{assign var="tmp" value="0"}
{section name=cat_num loop=$subcategories}
{if $subcategories[cat_num].category}{assign var="tmp" value="1"}{/if}
{/section}


{* ==================== Sub categories mod start *}

{section name=cat_num loop=$subcategories}
{ if %cat_num.first% }
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
{/if}
{ if %cat_num.index% is div by 2}
<tr>
{/if}
<td align="center" valign="top">
<a title="Alternate Text" href="home.php?cat={ $subcategories[cat_num].categoryid }">
[img]{$xcart_web_dir}/icon.php?categoryid={$subcategories[cat_num].categoryid}[/img]

<font size="3">{ $subcategories[cat_num].category|escape } </font></a>
{ $subcategories[cat_num].description|escape }
{if $config.Appearance.count_products eq "Y"}
{if $subcategories[cat_num].product_count}

({ $subcategories[cat_num].product_count } Items)
{elseif $subcategories[cat_num].subcategory_count}
({ $subcategories[cat_num].subcategory_count } Subcategories)
{/if}
{/if}
</td>
{ if %cat_num.last% }
</tr>
</table>
{/if}
{/section}

{* ==================== Sub categories mod end *}


{if $tmp and $products ne "" }
<BR clear="left">
<HR size="1" noshade>
{/if}
{if $products}
{if $sort_fields}
<DIV align="right">{include file="main/search_sort_by.tpl" sort_fields=$sort_fields selected=$search_prefilled.sort_field direction=$search_prefilled.sort_direction url="home.php?cat=`$cat`&"}</DIV>
{/if}
{if $total_pages gt 2}


{ include file="customer/main/navigation.tpl" }
{/if}
<HR size="1" width="100%">
{include file="customer/main/products.tpl" products=$products}
{/if}
{if $products eq "" and $tmp eq "0"}
{$lng.txt_no_products_in_man}
{/if}
{/capture}
{include file="dialog.tpl" title=$current_category.category content=$smarty.capture.dialog extra="width=100%"}
{if $products eq ""}
{if $f_products ne ""}



{include file="customer/main/featured.tpl"}
{/if}
{/if}
{ include file="customer/main/navigation.tpl" }


Jeremy

MCM 06-30-2006 01:36 PM

Oh, does anyone know what tag to add so (0 Items) appears when there are no items in a subcategory? Right now, (# Items) only shows up if the subcategory actually has items available.

Thanks,

Jeremy

kenlerch 07-06-2006 01:21 AM

Code Modified for use with DSEFU
 
Hey guys, I just got the code working with DSEFU's , v 4.0.17 Pro and figured it would be of use here since both seem to be a popular mod and I had seen at least one request in this thread.

Notes:
* This is the entire code for subcatecories.tpl
* Modified per Balinor's post on page 8 to use file system for images instead of a call to the database
* This code uses 4 columns. You have to set n in "div by n" to the (number of columns + 1). I also changed the width of the table to work with four columns, thus the "25%". Just change that value to the appropriate number for your number of columns (33% for 3, 20% for 5, etc).
* I used an image height of 50, so you may need to change that to your needs as well.

Thanks for this mod, it's definitely a good one. And thanks for this forum in general. I've found lots of good stuff here and figured I'd give something back with this post.

Code:

{* $Id: subcategories.tpl,v 1.43.2.2 2004/10/07 07:08:51 max Exp $ *}
{if $active_modules.Bestsellers ne "" and $config.Modules.bestsellers_menu ne "Y"}


 
{include file="modules/Bestsellers/bestsellers.tpl"}
{/if}


 
{if ($navigation_page eq "")||($navigation_page eq "1")}{$current_category.description|regex_replace:"/[\n]/":"
"}

{/if}
{capture name=dialog}
{assign var="tmp" value="0"}
{section name=cat_num loop=$subcategories}
{if $subcategories[cat_num].category}{assign var="tmp" value="1"}{/if}
{/section}

{* ==================== Sub categories mod start *}
{foreach from=$subcategories item=subcat name="subcats"}
{ if $smarty.foreach.subcats.first }
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
{/if}
{ if $smarty.foreach.subcats.iteration is div by 5}
<tr>
{/if}
<td align="center" valign="top" width="25%">
<a href="{seo_link cat_name=$subcat.category cat_id=$subcat.categoryid}">
{if $subcat.icon_url}[img]{$subcat.icon_url}[/img]{else}[img]{$xcart_web_dir}/default_image.gif[/img]{/if}
</a>
 
<a href="{seo_link cat_name=$subcat.category cat_id=$subcat.categoryid}">
<font size="1">{$subcat.category|escape}</font></a>
 
{if $config.Appearance.count_products eq "Y"}
{if $subcat.product_count}{ $subcat.product_count }  {$lng.lbl_items}
{elseif $subcat.subcategory_count}{ $subcat.subcategory_count } {$lng.lbl_categories|lower}
{/if}
{/if}
</td>
{ if $smarty.foreach.subcats.last }
</tr>
</table>
{/if}
{/foreach}
{* ==================== Sub categories mod end *}

{if $tmp and $products ne "" }
<BR clear="left">
<HR size="1" noshade>
{/if}
{if $products}
{if $sort_fields}
<DIV align="right">{include file="main/search_sort_by.tpl" sort_fields=$sort_fields selected=$search_prefilled.sort_field direction=$search_prefilled.sort_direction url="home.php?cat=`$cat`&"}</DIV>
{/if}
{if $total_pages gt 2}

 
{ include file="customer/main/navigation.tpl" }
{/if}
<HR size="1" width="100%">
{include file="customer/main/products.tpl" products=$products}
{/if}
{if $products eq "" and $tmp eq "0"}
{$lng.txt_no_products_in_man}
{/if}
{/capture}
{include file="dialog.tpl" title=$current_category.category content=$smarty.capture.dialog extra="width=100%"}
{if $products eq ""}
{if $f_products ne ""}


 
{include file="customer/main/featured.tpl"}
{/if}
{/if}
{ include file="customer/main/navigation.tpl" }


photo 07-06-2006 04:19 AM

Quote:

Originally Posted by mffowler
Close, but use the file system for the cat. images. The code needs to be reworked using sections to allow for multiple columns (am trying it now), but here's your previous code with names and content and using the file system. I have left your database image call to see what was coded out...
Code:

{if $subcategories}
<table border="0" cellspacing="5" width="100%">
<tr>
{foreach from=$subcategories item=subcat}
  {if $tmp is not div by 2}
    </tr><tr valign="top">
  {/if}
<td class="SubcatTitle"><a href="home.php?cat={ $subcat.categoryid }" title="{ $subcat.category }">{if $subcat.icon_url}[img]{$subcat.icon_url}[/img]{else}[img]{$xcart_web_dir}/default_icon.gif[/img]{/if}

{*
[img]image.php?id={$subcat.categoryid}&amp;type=C[/img]
*}

</a>



<font class="ItemsList">{ $subcat.category|escape }</font>


{if $config.Appearance.count_products eq "Y"}
{if $subcat.product_count}{ $subcat.product_count } {$lng.lbl_products}
{elseif $subcat.subcategory_count}{ $subcat.subcategory_count } {$lng.lbl_categories|lower}
{/if}
        {/if}

</td>
{assign var="tmp" value=$tmp+1}
{/foreach}
</tr></table>
{/if}

- Mike


Did you ever make any progress on this?

Thanks

mrkenzie 07-08-2006 05:38 PM

This is the code that I have and works with 4.1.0. I have added several things to this modification. Not only will it display the categories in columns, it will:
1. display the default "No Image Avail." image if one is not assigned
2. display "0 Products" if there are no subcategories or products for a particular category.
3. it will show the subcategory DESCRIPTION if there is one when you hover over the subcategory link.

Take it, use it, modify it. Good luck!

Here is what you add to the Skin1.css
Code:

.ColumnTitles { padding-left: 5px; text-align: center; width: 33%; }

Find this in categories.php:
Code:

$_categories = func_query_hash("SELECT $to_search FROM $sql_tbl[categories] USE INDEX (am) $join_tbl ".(!empty($search_condition)?"WHERE ".implode(" AND ", $search_condition):"")." GROUP BY $sql_tbl[categories].categoryid ".$sort_condition, "categoryid", false);

and replace with this (in order to get the category description):
Code:

$_categories = func_query_hash("SELECT $to_search, $sql_tbl[categories].description FROM $sql_tbl[categories] USE INDEX (am) $join_tbl ".(!empty($search_condition)?"WHERE ".implode(" AND ", $search_condition):"")." GROUP BY $sql_tbl[categories].categoryid ".$sort_condition, "categoryid", false);

Here is the code that I changed in subcategories.tpl:
Code:

{if $subcategories}
<table cellspacing="5" width="100%" border="0">
<tr>
{foreach from=$subcategories item=subcat}

{if $tmp is div by 3}
    </tr><tr><td colspan="3"></td></tr><tr valign="top">
{/if}

{ if $tmp and $first_subcat ne "Y" }
        {assign var="tmp" value=0}
        {assign var="first_subcat" value="Y"}
{/if}

 <td class="ColumnTitles" valign="top"><a title="{$subcat.description}" href="home.php?cat={ $subcat.categoryid }"><img src="{if $subcat.icon_url}{$subcat.icon_url}{else}{$xcart_web_dir}/default_image.gif{/if}" alt="" />

        <font class="ItemsList">{ $subcat.category|escape }</font></a>

        {if $config.Appearance.count_products eq "Y"}
{if $subcat.product_count}{ $subcat.product_count } {$lng.lbl_products}
{elseif $subcat.subcategory_count}{ $subcat.subcategory_count } {$lng.lbl_categories|lower}
{else} 0 Products
{/if}
        {/if}
{assign var="tmp" value=$tmp+1}
{/foreach}
</table>
{/if}


By Default, it shows 3 columns. If you want to change the number of columns, then just change all the 3's to the number of columns you want in this line of code (from above):
Code:

{if $tmp is div by 3}
    </tr><tr><td colspan="3"></td></tr><tr valign="top">
{/if}

And then change the following line in skin1.css (from above) for the appropriate td width %
Code:

.ColumnTitles { padding-left: 5px; text-align: center; width: 33%; }

I added a blank row between each row of subcategories, just to seperate the rows a little so it does not look so crowded.

Let me know if there are any problems.

dalmuti 07-08-2006 06:14 PM

Excellent! Works fine in 4.1.2!

Thank you,

Louise

robf 07-08-2006 08:32 PM

Right on, I've been waiting a while for someone to get the right code, thanks a lot Mike, it works great on 4.1.2 :)

mffowler 07-08-2006 09:20 PM

Thanks Mike. Works beautifully and a great sign that the forum will commence it's move to supprting 4.1.x users....

- Mike


All times are GMT -8. The time now is 01:16 PM.

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