SEO WebMonkey

Web design & development with an ample sprinkle of SEO

RSS2.0 Feed
Magento – customising individual product category pages

Magento – customising individual product category pages

Magento's templating structure strikes me as a little odd in places, but is very capable. But capability invariably breeds complexity.

Task: change the number of columns and displayed products on individual category pages.

Magento uses a combination of xml layout directives and php/html (.phtml) template files to build the front-end interface (storefront) of a web shop. Fundamental changes to the look and feel of the store can and should be made directly in these files, all of which reside in the directory:

/app/design/frontend/default/

Smaller scale tweaks to page content can also be added from within the admin interface. Customising the content of an individual category page, for example, is achieved through adding xml code segments to the Custom Design tab of a category.

category-custom-design

The difficulty we found was that any customisations for an individual category were added to the page in addition to the standard category layout definitions, rather than replace them with a new, unique set of directives. Resulting, in our case, to duplicated elements on the page.

Solution 1: Create an additional template

The admin allows selection of an entirely different template for an individual category. A powerful option, that’s for sure, but hugely impractical for ongoing maintenance. Multiple templates means multiple changes to layout, phtml and possibly css files if any tweaks are required in the future.

Solution 2: Add category-specific custom code to the master layout xml file

The default category layouts are defined in /app/design/frontend/default/-your-template-/layout/catelog.xml (just look for the <catalog_category_default> element).

To add code for a specific category, all one needs to do is create a new element containing the internal ID of that category (changing XX to the category’s internal ID):

<CATEGORY_XX>
  ....
</CATEGORY_XX>

A good solution which fails only in that it becomes less portable. These xml files are designed to handle the template as a whole. Having specific category designations here mean the template can only be used for a single store with the correct category ID values.

Solution 3: Add custom xml code to the category via the Administration interface

The most practical solution, without a doubt. Here the custom code affects only the single category (and its child-categories should that be selected as an option).

However, both Solution 2 and Solution 3 must solve the problem that additional xml is added to the default xml. In our case, however, we must override the default settings to avoid duplication.

The unsetChild method

category-custom-designThankfully, Magento provides a means of overriding the default elements, as defined in the layout template, to be replaced by new elements. You can see the unsetChild methods implimented in the screenshot here.

unsetChild

The method tells magento to remove whatever definitions that have already been created for the named elements. Usually, these would have been defined in the main template xml files. It does not remove the named elements themselves, so you are then free to redefine those elements as you wish.

In our case, we wanted to replace the category.products, product_list, and product_list_toolbar elements to avoid duplicating the product grid.

Once unsetChild had been called, we were free to add our customised grid definition below it.

The results are a default, 3-column, 9 product grid for most of the catalog, but a 4-column, 12 product grid for some individual category pages.

The remove method

Magento also provides the ability to entirely remove elements from the xml definition.

<remove name="xxxx" />

This completely removes the defined element, by name. Inappropriate in our case, because it does not provide the option of re-inserting a new version of the element into the page; it removes that element name entirely.

7 Responses to “Magento – customising individual product category pages”

  1. Nice article on how to customize Magento Layout in right way. It’s very useful for me. Thank you for sharing it.

  2. rickahontas says:

    Thanks for the info, also, you can clear the entire content section by using:

    <reference name=”content”>
    <action method=”unsetChildren” />
    </reference>

    Cheers!

  3. The first solution which is creating another template is the most simplest there is. Recommended for people who has no idea of xml.

    Nice article and very informative. Really helpful for our new Magento developers at Magento Technologies.

    • ndixon says:

      Really? You consider creating and maintaining an entire additional theme directory structure just for a single page variation as a simpler solution than editing a line or two?

  4. Michael says:

    @ndixon

    Magento has hierarchical themes, so your new theme can consist of a single template file and everything else will refer to the higher up theme.

  5. Bruce says:

    Nice article on how to customize Magento Layout in right way. It’s very useful for me. Thank you for sharing it.

  6. Nick Weisser says:

    Solution 3 is just what I’ve been looking for. Thanks!

Leave a Reply

COMMENT APPROVAL POLICY: Please use a genuine name and email address for your comment. Please use your real name, not SEO keyword text. Please limit any outgoing links in your comment to a maximum of ONE, which should not be the same as you entered URL in the form. Please be considerate to other commenters. Please be relevant to the blog post and contribute to the discussion. Blatant link generation comments (we get a lot of those!) will be deleted. LICENSE By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution. Your comment may be edited or removed by a site admin if deemed necessary.

This site attempts to break down personal, practical experience of web development and SEO into easily accessible, digestible articles and information.

Neil Dixon has been involved in web development and SEO since the late 1990s and is currently responsible for SEO for an online media entertainment network.

Views and opinions contained on this site are those of the article author(s) and do not reflect those of any organisation to which they are affiliated.

Search dofollow blogs: