Fishpig Wordpress Magento发布问题 [英] Fishpig Wordpress Magento Post issue

查看:86
本文介绍了Fishpig Wordpress Magento发布问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How to retrieve recent posts on the basis of its corresponding category in fishpig wordpress magento integration?

推荐答案

$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"

The Fishpig Wordpress module registers the current wordpress category as 'wordpress_category'

因此,请在评论中回答有关如何动态获取当前wordpress类别的问题:

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

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

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?

这篇关于Fishpig Wordpress Magento发布问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆