Contrib - How to show category images on home page
10 posts
• Page 1 of 1
Contrib - How to show category images on home page
I know I ran across someone asking this question and I can't find that post again and I don't know if this has ever been answered, so I will post my solution. If it's a dupe, my apologies to the mods.
In -- controller > common > home.php -- I added it around line 25, right under this portion
I added
Then in -- view > theme > ThemeName > template > common > home.tpl
You can uncomment the print_r to see what is all available for you to work with.
I also implemented a lookup for SEO Friendly URLs, but it can be pretty database intensive for larger sites, so if anyone knows of a better way to doing this lookup then my way, please feel free to post it!
I added this to the controller, just beneath the first snippet.
Technically, this should be done from the category model, but since I am not the best at MySQL, I wasn't able to decipher the query that is currently being used.
Then, for the view, replace the previous snippet with this one.
Again, the store I used this on has 3 products and has no plans on adding more products. If you start adding hundreds or thousands of products using the above SEO URL lookup, you will be slamming your database pretty hard. I hope someone can post a followup to this with a better way to look this up.
Happy hacking!
In -- controller > common > home.php -- I added it around line 25, right under this portion
- Code: Select all
if (!$this->config->get('config_store_id')) {
$this->data['welcome'] = html_entity_decode($this->config->get('config_description_' . $this->config->get('config_language_id')), ENT_QUOTES, 'UTF-8');
} else {
$store_info = $this->model_setting_store->getStore($this->config->get('config_store_id'));
if ($store_info) {
$this->data['welcome'] = html_entity_decode($store_info['description'], ENT_QUOTES, 'UTF-8');
} else {
$this->data['welcome'] = '';
}
}
I added
- Code: Select all
$this->load->model('catalog/category');
$this->data['categories'] = $this->model_catalog_category->getCategories(0);
Then in -- view > theme > ThemeName > template > common > home.tpl
- Code: Select all
<ul id="catalog-nav">
<?php foreach($categories as $category): ?>
<?php // print_r($category); ?>
<li style="text-indent: 0;">
<a href="index.php?route=product/category&path=<?php echo $category['category_id'] ?>">
<img src="/store/image/<?php echo $category['image'] ?>" style="border:0;">
</a>
</li>
<?php endforeach; ?>
</ul>
You can uncomment the print_r to see what is all available for you to work with.
I also implemented a lookup for SEO Friendly URLs, but it can be pretty database intensive for larger sites, so if anyone knows of a better way to doing this lookup then my way, please feel free to post it!
I added this to the controller, just beneath the first snippet.
- Code: Select all
$cat_count = 0;
foreach($this->data['categories'] as $category){
$seo_url_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "url_alias WHERE query = 'category_id=" . $category['category_id'] . "'");
if ($seo_url_query->num_rows) {
$this->data['categories'][$cat_count]['seo_keyword'] = $seo_url_query->row['keyword'];
}
$cat_count++;
}
Technically, this should be done from the category model, but since I am not the best at MySQL, I wasn't able to decipher the query that is currently being used.
Then, for the view, replace the previous snippet with this one.
- Code: Select all
<ul id="catalog-nav">
<?php foreach($categories as $category): ?>
<?php // print_r($category); ?>
<li style="text-indent: 0;">
<?php if(isset($category['seo_keyword'])){ ?>
<a href="/store/<?php echo $category['seo_keyword'] ?>/">
<?php } else { ?>
<a href="index.php?route=product/category&path=<?php echo $category['category_id'] ?>">
<?php } ?>
<img src="/store/image/<?php echo $category['image'] ?>" style="border:0;">
</a>
</li>
<?php endforeach; ?>
</ul>
Again, the store I used this on has 3 products and has no plans on adding more products. If you start adding hundreds or thousands of products using the above SEO URL lookup, you will be slamming your database pretty hard. I hope someone can post a followup to this with a better way to look this up.
Happy hacking!
- deuce
- Posts: 31
- Joined: Fri Jul 02, 2010 5:40 pm
Re: Contrib - How to show category images on home page
this is working all i get is bullet points? on version 1.4.9.1
- aaron1988
- Posts: 256
- Joined: Thu Jan 27, 2011 2:03 am
Re: Contrib - How to show category images on home page
There is a mod called Categories Home which handles this beautifully without any need for modifying the core code.
- marc_cole
- Posts: 217
- Joined: Tue Dec 14, 2010 3:26 am
- Location: Seattle, WA
Re: Contrib - How to show category images on home page
Advanced Categories Module Features:
1) Front block name settings in admin panel.
2) Positions: Home, Left, Right.
3) Subcategories settings (show/hide).
4) Categories images settings (show/hide).
5) Categories images size settings (max.width / max height).
6) 3 languages (english, russian, ukrainian).
7) Module can work together with Category module.
1) Front block name settings in admin panel.
2) Positions: Home, Left, Right.
3) Subcategories settings (show/hide).
4) Categories images settings (show/hide).
5) Categories images size settings (max.width / max height).
6) 3 languages (english, russian, ukrainian).
7) Module can work together with Category module.
-

webmix - Posts: 23
- Joined: Mon Apr 04, 2011 6:03 pm
- Location: Ukraine, Dnepropetrovsk
Re: Contrib - How to show category images on home page
How can I use this script to show category images in the header? Now I have showing an image per category on category page. But I want them to show in the header. Thanks for help.
- remcofaasse
- Posts: 48
- Joined: Sun Dec 04, 2011 6:20 pm
Re: Contrib - How to show category images on home page
webmix wrote:Advanced Categories Module Features:
1) Front block name settings in admin panel.
2) Positions: Home, Left, Right.
3) Subcategories settings (show/hide).
4) Categories images settings (show/hide).
5) Categories images size settings (max.width / max height).
6) 3 languages (english, russian, ukrainian).
7) Module can work together with Category module.
Will this work with opencart 1.5.x.x ?
- scanreg
- Posts: 601
- Joined: Wed May 05, 2010 4:15 pm
Re: Contrib - How to show category images on home page
marc_cole wrote:There is a mod called Categories Home which handles this beautifully without any need for modifying the core code.
Has this been solved??? Is there a new module for the latest version 1.5.1.3? By the way marc_cole, I tried to see if this would work with the new one but it doesn't. Just a blank screen when trying to edit. Also, in viewing comments on the module, people are saying it's not the categories that are featured?
- gymrat29
- Posts: 4
- Joined: Mon Aug 16, 2010 4:38 pm
Re: Contrib - How to show category images on home page
scanreg wrote:webmix wrote:Advanced Categories Module Features:
1) Front block name settings in admin panel.
2) Positions: Home, Left, Right.
3) Subcategories settings (show/hide).
4) Categories images settings (show/hide).
5) Categories images size settings (max.width / max height).
6) 3 languages (english, russian, ukrainian).
7) Module can work together with Category module.
Will this work with opencart 1.5.x.x ?
Yeah, what he said??????????????????????????????
- gymrat29
- Posts: 4
- Joined: Mon Aug 16, 2010 4:38 pm
Re: Contrib - How to show category images on home page
i think there is a contrib around called Category Wall that might do this
- scanreg
- Posts: 601
- Joined: Wed May 05, 2010 4:15 pm
Re: Contrib - How to show category images on home page
scanreg wrote:i think there is a contrib around called Category Wall that might do this
Awesome! Thanks, that's just what I was looking for.

- gymrat29
- Posts: 4
- Joined: Mon Aug 16, 2010 4:38 pm
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 11 guests













