Fishpig Wordpress Magento Post问题

Nid*_*ida 0 magento magento-1.7 fishpig

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

Dre*_*ter 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)
;
Run Code Online (Sandbox Code Playgroud)

编辑

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

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

Mage::registry('wordpress_category');
Run Code Online (Sandbox Code Playgroud)

上面的完整示例将变为:

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

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