Magneto Fishpig – Adding Blog Categories to top level nav

The Magento Fishpig extension is great, but in fully integrated mode it’s not that easy to use – put it this way, you have to be a lot better at Magento than at WordPress to get it all working. Let’s say you want more than one of the top level Magento navigation items to link to a blog category. Lets assume that you’ve set up your Magento navigation, and you have pointed two of the main links to Magento CMS pages ‘testimonials’ and ‘news’. You can refer to this post for more info on that.

You would create categories in the WordPress installation for Testimonials and News and add your posts. Now comes the sneaky bit. You would use the URL Rewrite Management section of Magento to rewrite the links to your Magento CMS pages to the relevant categories in WordPress. Here’s a screenshot for the 301 rewrite passing the news CMS page over to the http://www.fairliefurniture.co.uk/handmade-hardwood-furniture/category/news/ archive list for Fairlie Furniture;

You can also change wordpress/post/list.phtml to pull posts for a specific category.


$categoryId = 1; //Replace with your category id
$postCollection = Mage::getModel('wordpress/post')->getCollection()
    ->addIsPublishedFilter()
    ->addCategoryIdFilter($categoryId)
    ->setOrder('post_date', 'desc')
;

To apply that to the homepage you would change wordpress.xml as follows;


	<wordpress_homepage_index>
		<update handle="wordpress_default"/>
		<reference name="content">
			<block type="wordpress/homepage" name="wordpress_homepage" template="wordpress/homepage.phtml">
				<block type="wordpress/post_list" name="wordpress_post_list" template="wordpress/post/customlist.phtml">
					<block type="wordpress/post_list_pager" name="wordpress_post_list_pager"/>
				</block>
			</block>
		</reference>
	</wordpress_homepage_index>

and set the homepage template to customised version of list.phtml;


<?php
$categoryId = 1; //Replace with your category id
$postCollection = Mage::getModel('wordpress/post')->getCollection()
    ->addIsPublishedFilter()
    ->addCategoryIdFilter($categoryId)
    ->setOrder('post_date', 'desc')
;
?>

<div class="post-list">
     <?php foreach($postCollection as $post): ?>