Tag Archives: Static Blocks

Magento Training In London and Manchester

Apologies to readers who have waited 8 weeks for a post, it has however I assure you been worth the wait!

I am really delighted to announce that I will begin running Magento training sessions at the end of August. 3 different courses are planned, however, to begin with I will be running pilot one-day courses in London and Manchester titled:

Magento 
Theming 
for 
Front‐End
 Developers

As the name suggests it will be targeted at front end developers and will look at theming Magento. The course will briefly cover some of the materials available on the Magento website before moving on to some, if not all, of the following areas:

  • Best Practices for Theming
  • Understanding XML Layouts
  • Working with Blocks, Properly!
  • Working with Categories and Navigation
  • Image Manipulation using Varien Objects
  • Question and Answer Session

I am also still open to further suggestions, if you get your ideas in quick!

Because the course is a pilot I will be offering a 40% discount on the standard seat price, places will be limited and some seats have already been reserved. There will be one pilot in Manchester and another in London so at least one should be accessible to most UK-based developers.

Interested parties are welcome to comment on this post and join the queue, with no obligation to sign up. Those that do will be sent an e-mail a few days before the tickets go on general release. A full itinerary and seat price will be released in the next fortnight.

Look forward to meeting some of you at the end of the month!

Darryl :-D

Tips For Creating Dynamic Category Landing Pages

This is quite a common want, so I thought I would put together a quick tutorial with some ideas and pointers. My main goal will be to give you a starting point for building a static block and PHTML file that can be applied to top level categories to dynamically create a block with of all the subcategories.

The first thing to do is create a new static block (CMS → Static Blocks), lets call it ‘Dynamic Landing Pages’. Within the content paste this:

{{block type="catalog/navigation" name="catalog.category" template="catalog/category/list.phtml"}}

If you’ve not seen one of these before, then basically it loads the list.phtml into the block allowing you to include dynamic content in your site.

Next create list.phtml in app/design/frontend/default/your_theme/template/catalog/category/

Then go to ‘Manage Categories’ select the relevant category and then choose ‘Static Block Only’ in the ‘Display Mode’ dropdown and then choose the ‘Dynamic Landing Pages’ static block we’ve just created from the ‘CMS Block’ dropdown.

Now to look at some coding to put in list.phtml, to get the category id of the current category and an array containing the ids of its child categories, use the following:

?Download list.phtml
1
2
3
4
$current = $this->getCurrentCategory()->getId();
$category = Mage::getModel('catalog/category')->load((int)$current);
$children = $category->getChildren();
$children = explode(",",$children);

This leaves you with:
$current, your current category id.
$category, which is an instance of Mage_Catalog_Model_Category.
$children, is an array of the child category ids.

Then cycle through each of the child categories by loading the category object using the id from the array. We check first that the first value is not just an empty string (as it will be if there are no categories):

?Download list.phtml
5
6
7
8
9
10
11
12
if (strlen($children[0]) > 0)
{
	foreach($children as $child)
	{
		$_child = Mage::getModel('catalog/category')->load($child);
			// then use the $_child object to pull out category properties
	}
}

Some of the key methods that I then subsequently used to create the landing pages were:

  • $_child->getName()
  • $_child->getUrl()
  • $_child->getImageUrl()
  • $_child->getProductCount()

The Image URL is based on the image that is uploaded in the ‘General Information’ tab in ‘Manage Categories’ but be aware that if you use this functionality you will probably want to edit frontend/default/your_theme/template/catalog/category/view.phtml so that it doesn’t load that image at the top of the subcategory.

To view the methods of the Mage_Catalog_Model_Category class look at the file: app/code/core/Mage/Catalog/Model/Category.php.

Comments and questions welcome :)