Fishpig Wordpress Magento Post问题

时间:2012-08-02 09:08:18

标签: magento magento-1.7 fishpig

如何根据fishpig wordpress magento集成中的相应类别检索最近的帖子?

1 个答案:

答案 0 :(得分:8)

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

修改

Fishpig Wordpress模块​​将当前的wordpress类别注册为'wordpress_category'

所以回答评论中关于如何动态获取当前wordpress类别的问题:

Mage::registry('wordpress_category');

上面的完整示例将成为:

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

但你可能应该使用Fishpig_Wordpress_Block_Category_View块,它可以让你从你的模板中访问$this->_getPostCollection()基本上完成以上所有操作 - 为什么你在使用fishpig模块时自己编码?