PrestaShop subcategories as grid

Today i want to show you how to change subcategories view in your prestashop store. By default prestashop in version 1.5.x displays subcategories in list with descriptions. I will show step by step how you can easily change it.  Are you ready  to display subcategories as a grid?  so, let's go ;)

 

default subcategories view in default prestashop template

prestashop and default display method of subcategories

 

 

And we want to modify view of the list to:

 

 

default prestashop theme and subcategories grid display

prestashop subcategories grid display

 

What we have to change?

We will modify two things, theme category.tpl file and it's css styles from category.css stylesheet file. From category.tpl file we will remove the subcategory description (we will move it to the category image alternative text). In the css styles file we will change appearance of the categories list.

 

 

Category.tpl template file contents

We will edit category.tpl file located in your theme directory (themes/your_theme/category.tpl). So please open this file. If you're using default theme - search for code that i pasted below. If you use non-default template - whole code should looks similar. Here it is, a piece of prestashop subcategories code:

<div id="subcategories">
			<h3>{l s='Subcategories'}</h3>
			<ul class="inline_list">
			{foreach from=$subcategories item=subcategory}
				<li class="clearfix">
					<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" title="{$subcategory.name|escape:'htmlall':'UTF-8'}" class="img">
						{if $subcategory.id_image}
							<img src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default')|escape:'html'}" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" />
						{else}
							<img src="{$img_cat_dir}default-medium_default.jpg" alt="" width="{$mediumSize.width}" height="{$mediumSize.height}" />
						{/if}
					</a>
					<a href="{$link->getCategoryLink($subcategory.id_category, $subcategory.link_rewrite)|escape:'htmlall':'UTF-8'}" class="cat_name">{$subcategory.name|escape:'htmlall':'UTF-8'}</a>
					{if $subcategory.description}
						<p class="cat_desc">{$subcategory.description}</p>
					{/if}
				</li>
			{/foreach}
			</ul>
			<br class="clear"/>
</div>

 

Remove the subcategory description

We have to removesubcategory description from code mentioned above. Subcategory description code looks like:

{if $subcategory.description}
    <p class="cat_desc">{$subcategory.description}</p>
{/if}

You can remove it or comment it (maybe it the future you will want to use it one again.. who knows?). To comment the code use smarty {* comment *} method:

{*
 {if $subcategory.description}
    <p class="cat_desc">{$subcategory.description}</p>
{/if}
*} 

 

We don't want to lose seo. Let's move the description in the image alt tag

As you notied above, category description variable looks like: {$subcategory.description}. We will use it in the alt="" tag. Here is the code for it:

{if $subcategory.id_image}
    <img src="{$link->getCatImageLink($subcategory.link_rewrite, $subcategory.id_image, 'medium_default')|escape:'html'}" alt="{if $subcategory.description}{$subcategory.description}{/if}" width="{$mediumSize.width}" height="{$mediumSize.height}" />
{else}
    <img src="{$img_cat_dir}default-medium_default.jpg" alt="{if $subcategory.description}{$subcategory.description}{/if}" width="{$mediumSize.width}" height="{$mediumSize.height}" />
{/if}

Use code above instead old one. Save changes.  Make sure that you've got force compilation turned to on. It's necessary while you're workin on template files. After all, you can turn force compile off. Okay, now it's time to css styles.

 

Css stylesheet file modification

Open the category.css file located in css subdirectory. (themes/your_theme/css/category.css). This is file with css styles related to the category page. 

 

Display subcategories block as a block

First important change is related to the whole #subcategories div block. We need to change its styles to block. In category.css file near the line 36 you've got something like:

#subcategories {
margin-top: 15px;
}

change it to:

#subcategories {
margin-top: 15px;
clear:both;
display:block;
overflow:hidden;   
}

 

Change subcategories list to grid

Now it's time to the most important thing in whole process. We need to change <li> objects. <li> objects is a row with subcategory photo and subcategory name. By default <li> objects appear as a list. To display each <li> as an "element" of grid, we have to change <li> object css styles. In category.css file near line 50 you've got code:

.inline_list li {
  padding: 10px 0;
  border-bottom: 1px dotted #ccc;
}

change it to:

.inline_list li {
  text-align: center;
  float: left;
  display: inline-block;
  width: 96px;
  height: 100px;
  border: 1px dotted #ccc;
  margin: 4px;
}

 

It's almost everything...

prestashop subcategories grid image problem


As you probably noticed, category images arent in the middle of the box, in this case it's necessary to change their css styles too.  And this is what we want to achieve:

prestashop subcategory grid

 

 

In the category.css file near line 54 you've got:

.inline_list li .img {
  float: left;
  margin-right: 15px;
}

change it to:

.inline_list li .img {
  display: block;
  float: left;
  margin-top: 15px;
}

 

And the effect is

 

prestashop subcategories grid display

 

if you have any questions related to this tutorial - feel free to start discussion in the comments field below. Thanks!

author milos myszczuk
Article by Milosz Myszczuk PrestaShop expert, official PrestaShop community moderator. PHP developer, specialist in relative and spatial databases management, GIS Analyst, CEO & founder of VEKIA interactive agency. Read more about VEKIA company
If you like my articles and want much more valuable tips, feel free to send me donation
1.4 version 1.4.11 1.6 404 addon admin advertise ahref ajax alpha animation api app application authentication back office backup badge banner basics block bootstrap button cache carrier cart catalog category certificate changelog chat class clear client clip cms code colors columns comments configuration contact container content controller cookie counter country coupon css csv currency customer dashboard database debug default delete delivery desktop developer device disable discount displayNav displayTop download dynamic editor effect empty encrypt engine error exchange exclude export facebook faceshop fade fancoupon fancybox fanpage fatal feature feed field file fix fixed font footer free friendly url front ftp full gallery generate gift global godaddy google google+ gray grid groupon header help hide highlight homefeatured homepage hook hosting hover howto htaccess html html5 ID image import include input instagram installation integration iPhone issue javascript jquery kgb knowhow languages law left likebox link list livingsocial loading log login logo loyality mail mailing maintenance manufacturer marketing marquee mcrypt menu meta mobile modification module movie moving multilanguage multiupload must have mysql news newsletter notification number open graph order override page password performance PHP phpmyadmin picture pinterest plugin popup post prestashop prestashop 1.0 prestashop 1.1 prestashop 1.2 prestashop 1.3 prestashop 1.4 prestashop 1.5 price rules problem product profile promotion proslider purifier quantity query quick tip random rates register reinsurance release reporting reset responsive restore results ribbon rich text right sales search security seo service shadow share shipping shop shopmania slider smarty social networks SQL SSL statistics stock store style subcategory superuser support switcher tab tablet tag tax template text theme tinyMCE tips and tricks tpl tracking translations tree trends trigger tumblr tutorial twitter update upgrade upload variables video visits voucher vulnerability web2print wide widget width window wishlist wysiwyg youtube zip zopim