Fishpig Wordpress Magento Post issue

北城以北 提交于 2019-12-23 04:56:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!