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)
-   -   Category images on front page (https://forum.x-cart.com/showthread.php?t=64542)

mekon 08-10-2012 06:30 AM

Category images on front page
 
Hello, ive been searching for a long time on this and I can't believe its not a standard thing in xcart.
Ive looked at older post which give me some code but not of them work.

All I want to do is show a list (which would be blocks, divs etc) of all my main categories. I need it to show the category image and it to link to the category when clicked on...like this basically: http://www.knight-air.co.uk/

I know this bit of code display the subcategories, but how can I change it to use on the home page to display the root categories

Code:

{foreach from=$categories item=subcategory}
      <a href="home.php?cat={$subcategory.categoryid}"><img src="{get_category_image_url category=$subcategory}" alt="{$subcategory.category|escape}" width="{$subcategory.image_x}" height="{$subcategory.image_y}" /></a>
    <br />
    <a href="home.php?cat={$subcategory.categoryid}">{$subcategory.category|escape}</a><br />
{/foreach}




It would be a great idea if there was a knowledge base of snippets of code then people could use it as a reference.


Thanks in advance.

totaltec 08-13-2012 01:41 PM

Re: Category images on front page
 
Hi mekon. This is where we keep our code snippets! Agreed it would be nice if they were organized...

Well I mocked up some code for you. Try adding this to /common_files/customer/main/welcome.tpl
PHP Code:

{foreach from=$categories_menu_list item=category name=front_cats}

  <
span class="subcategories" style="min-width: {$subcat_div_width}px; width: {$subcat_div_width}px; min-height: {$subcat_div_height}px;">
    {if 
$category.is_icon}
      <
a href="home.php?cat={$category.categoryid}"><img src="{get_category_image_url category=$category}" alt="{$category.category|escape}width="{$category.image_x}height="{$category.image_y}/></a>
    {else}
      <
img src="{$ImagesDir}/spacer.gif" alt="" width="1" height="{$subcat_img_height}/>
    {/if}
    <
br />
    <
a href="home.php?cat={$category.categoryid}">{$category.category|escape}</a><br />
    {if 
$config.Appearance.count_products eq "Y"}
      {if 
$category.product_count}
        {
$lng.lbl_N_products|substitute:products:$category.product_count}
      {elseif 
$category.subcategory_count}
        {
$lng.lbl_N_categories|substitute:count:$category.subcategory_count}
      {/if}
    {/if}
  </
span>

{/foreach} 


mekon 08-14-2012 02:17 AM

Re: Category images on front page
 
Brilliant Mike, what a star you are.

Before I moved to xcart I used Actinic (now sellerdeck) and they have a knowledge base of tricks etc: http://community.sellerdeck.com/forumdisplay.php?f=27

Which proved really useful for developers. Maybe they will do something similar in the future.

Thanks again.

M

mekon 08-15-2012 03:18 AM

Re: Category images on front page
 
Mike, sorry to bother you

For some reason when I move from the home page to another, then come back the categories are gone. If I run cleanup.php they appear again....until I goto another page and back etc.

Any idea what this could be?

M

mekon 08-15-2012 05:22 AM

Re: Category images on front page
 
Ok, ive tested this in the default templates in 4.5.2, and it does the same.

I also tried it in a 4.4.2 site (same server etc) and it retains them...so something about the code that 4.5.2 doesn't like?

mekon 08-15-2012 10:29 AM

Re: Category images on front page
 
Phil found the fix:

Main page :: General settings :: Flyout Menus

Cache the menu = OFF

paul@dimoda.com.au 08-23-2012 01:20 PM

Re: Category images on front page
 
Quote:

Originally Posted by totaltec
Hi mekon. This is where we keep our code snippets! Agreed it would be nice if they were organized...

Well I mocked up some code for you. Try adding this to /common_files/customer/main/welcome.tpl
PHP Code:

{foreach from=$categories_menu_list item=category name=front_cats}

  <
span class="subcategories" style="min-width: {$subcat_div_width}px; width: {$subcat_div_width}px; min-height: {$subcat_div_height}px;">
    {if 
$category.is_icon}
      <
a href="home.php?cat={$category.categoryid}"><img src="{get_category_image_url category=$category}" alt="{$category.category|escape}width="{$category.image_x}height="{$category.image_y}/></a>
    {else}
      <
img src="{$ImagesDir}/spacer.gif" alt="" width="1" height="{$subcat_img_height}/>
    {/if}
    <
br />
    <
a href="home.php?cat={$category.categoryid}">{$category.category|escape}</a><br />
    {if 
$config.Appearance.count_products eq "Y"}
      {if 
$category.product_count}
        {
$lng.lbl_N_products|substitute:products:$category.product_count}
      {elseif 
$category.subcategory_count}
        {
$lng.lbl_N_categories|substitute:count:$category.subcategory_count}
      {/if}
    {/if}
  </
span>

{/foreach} 



This is a superstar piece of code and I also do not know why it is not standard in x-cart...

I was able to simple drop this code into a static page and voila - there is my category listing!

DBK Web Builder 04-26-2014 06:22 PM

Re: Category images on front page
 
Worked perfectly - in 4.6

Thanks !!

DBK Web Builder 10-23-2014 08:50 AM

Re: Category images on front page
 
Quote:

Originally Posted by paul@dimoda.com.au
This is a superstar piece of code and I also do not know why it is not standard in x-cart...

I was able to simple drop this code into a static page and voila - there is my category listing!


How did you drop this into a static page ?

All it shows is code ?

qualiteam 10-24-2014 12:24 AM

Re: Category images on front page
 
You are to enable Smarty tags in static pages first:
http://help.x-cart.com/index.php?title=X-Cart:Static_Pages


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

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