Magento – Add a category link to a CMS page

cmslinkmagento-1.9

I have a CMS landing page and it will contain links to my store categories – I currently have the following setup:

<a href="#" class="this-class">Some text here...</a>
<a href="#" class="this-class">Some text here...</a>
<a href="#" class="this-class">Some text here...</a>

I realise I can add a link in the usual way (e.g. mydomain.com/mycategory) but I want to add in such a way that should the category be updated in the future the link won't break.

Is this done via the "store url" method? I've seen that there's a widget that can do this but I need to keep the tags and classes shown above. So, I'm looking for a solution that will simply replace the "#".

Best Answer

This can not be done directly with CMS page, for example:

If you want to call category URL to link you can do statically like this

<a href="{{store direct_url='category-url.html'}}" class="this-class">Some text here...</a>

But if in future if your category URL is changed it will not work for you.

For that you will need to set it dynamically. And you will need to add block with template path and call it in CMS page like

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

And in category.phtml file you can get the store category collection and use that:

<?php
    $helper = Mage::helper('catalog/category');
    $categories = $helper->getStoreCategories();
?>
Related Topic