问题
How to retrieve recent posts on the basis of its corresponding category in fishpig wordpress magento integration?
回答1:
$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?
来源:https://stackoverflow.com/questions/11774330/fishpig-wordpress-magento-post-issue