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

Category images on front page

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 08-10-2012, 06:30 AM
 
mekon mekon is offline
 

Senior Member
  
Join Date: Jan 2011
Posts: 180
 

Default 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.
__________________
------------------------------------------------

Darren
Reply With Quote
  #2  
Old 08-13-2012, 01:41 PM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default 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} 
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote

The following 2 users thank totaltec for this useful post:
mekon (08-14-2012), paul@dimoda.com.au (08-23-2012)
  #3  
Old 08-14-2012, 02:17 AM
 
mekon mekon is offline
 

Senior Member
  
Join Date: Jan 2011
Posts: 180
 

Default 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
__________________
------------------------------------------------

Darren
Reply With Quote

The following user thanks mekon for this useful post:
totaltec (08-14-2012)
  #4  
Old 08-15-2012, 03:18 AM
 
mekon mekon is offline
 

Senior Member
  
Join Date: Jan 2011
Posts: 180
 

Default 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
__________________
------------------------------------------------

Darren
Reply With Quote
  #5  
Old 08-15-2012, 05:22 AM
 
mekon mekon is offline
 

Senior Member
  
Join Date: Jan 2011
Posts: 180
 

Default 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?
__________________
------------------------------------------------

Darren
Reply With Quote
  #6  
Old 08-15-2012, 10:29 AM
 
mekon mekon is offline
 

Senior Member
  
Join Date: Jan 2011
Posts: 180
 

Default Re: Category images on front page

Phil found the fix:

Main page :: General settings :: Flyout Menus

Cache the menu = OFF
__________________
------------------------------------------------

Darren
Reply With Quote
  #7  
Old 08-23-2012, 01:20 PM
 
paul@dimoda.com.au paul@dimoda.com.au is offline
 

Senior Member
  
Join Date: Aug 2007
Location: Perth, Australia
Posts: 148
 

Default 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!
__________________
X-Cart Gold 4.1.10, 4.1.18, 4.4.4, 4.4.5
Reply With Quote
  #8  
Old 04-26-2014, 06:22 PM
 
DBK Web Builder DBK Web Builder is offline
 

Advanced Member
  
Join Date: Apr 2014
Location: NJ
Posts: 67
 

Default Re: Category images on front page

Worked perfectly - in 4.6

Thanks !!
__________________
4.6.2 and 4.6.3
http://www.DBKWebBuilder.com
Reply With Quote

The following user thanks DBK Web Builder for this useful post:
totaltec (04-27-2014)
  #9  
Old 10-23-2014, 08:50 AM
 
DBK Web Builder DBK Web Builder is offline
 

Advanced Member
  
Join Date: Apr 2014
Location: NJ
Posts: 67
 

Default 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 ?
__________________
4.6.2 and 4.6.3
http://www.DBKWebBuilder.com
Reply With Quote
  #10  
Old 10-24-2014, 12:24 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default 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
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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:20 AM.

   

 
X-Cart forums © 2001-2020