Custom Category Templates and CSS in OpenCart 1.5 +

Custom Category Templates and CSS in OpenCart 1.5 +

Custom Category Templates and Custom Category CSS for OpenCart relates to the following tested versions:

OpenCart version(s):  1.5.0, 1.5.0.1, 1.5.0.2, 1.5.0.3, 1.5.0.4, 1.5.0.5

> Newly tested on OpenCart 1.5.1.1 and works

This was tested today on OpenCart v 1.5.0.5 today and was working flawlessly.

Ever wanted to have a custom category template (hard coded elements) On certain categories – or to totally change the layout completely?  Or maybe you’d just like different CSS?

These instructions relate to the default theme of OpenCart but should work for any theme provided you change the default bit with the themes name!

Open: catalog/controller/product/category.php

Find (Line 329):

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
$this->template = $this->config->get('config_template') . '/template/product/category.tpl';
} else {
$this->template = 'default/template/product/category.tpl';
}

Replace With:

//start custom category design by ItsAdam.co.uk
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/product/category.tpl')) {
if ($category_id == 1) { //Category 1
$this->template = $this->config->get('config_template') . '/template/product/category1.tpl';
} elseif ($category_id == 2) { //Category 2
$this->template = $this->config->get('config_template') . '/template/product/category2.tpl';
} elseif ($category_id == 3) { //Category 3
$this->template = $this->config->get('config_template') . '/template/product/category3.tpl';
} elseif ($category_id == 4) { //Category 4
$this->template = $this->config->get('config_template') . '/template/product/category4.tpl';
} else { //default
$this->template = $this->config->get('config_template') . '/template/product/category.tpl';
}
} else {
$this->template = 'default/template/product/category.tpl';
}
//end custom category design

For our new custom categories we will need to create the templates so that they’re viewable and custom.

Find: catalog/view/theme/product/category.tpl

And duplicate it and name it inline with the naming in the above code, ie category1.tpl etc etc

This OpenCart Mod is published for free to the Community, if you require more extensive modifications or OpenCart Themes, contact by email:

opencart at itsadam.co.uk

Sorry for the anti-spam measure, I get lots of traffic and even more spam 🙁

New! Download these instructions in plain text format (handy if you copy and paste and it’s not working or wordpress ignores the code tag).

Download the Instructions in Plain Text Format

 

5 Responses

  1. Adam says:

    This tutorial will also work with OpenCart 1.5.1.1 and above 🙂

  2. Adam says:

    Fixed and Text Document Instructions Link Added!

  3. Kyle U says:

    Hey Adam!

    How difficult would it be to define a custom template for any subcategory of a specified parent category?

  4. Adam says:

    Very easy, I’ve actually got some code for where I’ve done that for a client.

    I’ll do another post for it, good for the SEO isn’t it 🙂

  5. Tom says:

    Thanks for this. works a charm.
    how would you go about doing the same for the product.tpl view of X category?

    I’ve tried using the same code on the product.php controller but I get a syntax error for the else comment.

    Would be great if you can help
    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *