Fishpig Wordpress Magento Post issue

3.9k views Asked by At

How to retrieve recent posts on the basis of its corresponding category in fishpig wordpress magento integration?

1

There are 1 answers

5
Drew Hunter On BEST ANSWER
$numPostsToShow = 2;
$categoryId = 1; //Replace with your category id
$recentPostCollection = Mage::getModel('wordpress/post')->getCollection()
    ->addIsPublishedFilter()
    ->addCategoryIdFilter($categoryId)
    ->setOrder('post_date', 'desc')
    ->setPageSize($numPostsToShow)
;

EDIT

The Fishpig Wordpress module registers the current wordpress category as 'wordpress_category'

So to answer the question in the comments as to how to get the current wordpress category dynamically:

Mage::registry('wordpress_category');

The full example above would then become:

$numPostsToShow = 2;
$categoryId = Mage::registry('wordpress_category')->getId();
$recentPostCollection = Mage::getModel('wordpress/post')->getCollection()
    ->addIsPublishedFilter()
    ->addCategoryIdFilter($categoryId)
    ->setOrder('post_date', 'desc')
    ->setPageSize($numPostsToShow)
;

But you should probably be using the Fishpig_Wordpress_Block_Category_View block which will give you access to $this->_getPostCollection() from within your template that essentially does everything above - why would you be coding this yourself when using the fishpig module?