Fishpig WordPress的Magento的帖子问题(Fishpig Wordpress M

2019-09-20 15:29发布

如何检索fishpig WordPress的Magento的整合其相应类别的基础上,最近的职位?

Answer 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)
;

编辑

所述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模块时被编码这个自己?



文章来源: Fishpig Wordpress Magento Post issue