Magento Themes and Magento Extensions

Magento Tips and Snippets


Magento has become quite a popular system in recent months.. snippets, tutorials, and other resources are in high demand for the system. Let’s look at some pros and cons of Magento and then some useful code snippets..

The Good

All around, Magento beats the competition. Here are just a few highlights if you’re not familiar with Magento:

  • Magento is Object Oriented
  • Magento is secure and scalable
  • Magento has a large community that is rapidly growing
  • Magento can be extended very easily
  • Magento allows for multiple stores and store fronts

The Bad

Magento has a few things that I’m not too excited about:

  • Magento is HUGE and bulky
  • Magento lacks a WYSIWIG and CMS
  • Magento uses a lot of JavaScript in a bad way

Some Useful Code

I’ll feed you baby birds..

Add a CMS Static Block to a page:
Within Magento:

{{block type="cms/block" block_id="identifier"}}

With PHP:

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('identifier')->toHtml() ?>

Display products from a specific category on the page:
Many people ask how to display products on the home page.. this is the easiest and most universal solution. Replace category ID with whatever category you want to display

{{block type="catalog/product_list" template="catalog/product/list.phtml" catagory_id="0"}}

Store URL within Magento:

{{store url=""}}

Define a new CMS Page Layout

Depending on what version of Magento you’re running, this may be different, but in the 1.3x series, this is how you’d define a new page layout. We’ll define a layout called home for this example:


                <empty module="page" translate="label">
                <one_column module="page" translate="label">
                    <label>1 column</label>
                <two_columns_left module="page" translate="label">
                    <label>2 columns with left bar</label>
                <two_columns_right module="page" translate="label">
                    <label>2 columns with right bar</label>
                <three_columns module="page" translate="label">
                    <label>3 columns</label>

Please understand that this is editing the core and will not be protected in an upgrade/update. To properly define this to be compatible with future upgrades, you’ll need to define a simple module to override the core with a local file.

Comments are closed.