php – 使用fishpig在magento类别页面上显示相关的博客文章/博客类别

我正在探索Magento的Fishpig扩展,并发现了一种有趣的方式来绑定博客文章&博客类别为magento的类别.但是,我没有得到如何在magento类别页面的前端显示.

我猜它在Fishpig模块的内置功能.

我尝试使用以下代码:

<catalog_category_view>
<reference name="left">
<block type="wordpress/post_associated" name="wordpress_posts_associated" template="wordpress/post/associated.phtml" after="-">
<action method="setTitle" translate="title" module="wordpress">
<title><![CDATA[Related Blog Posts]]></title>
</action>
<action method="setEntity">
<type><![CDATA[category]]></type>
</action>
</block>
</reference>
</catalog_category_view>

解决方法

If you wanted to display the direct associations against a category,you would need to retrieve the association from the database and build a post collection manually using the IDs retrieved.

要扩展Bens评论,帮助者Fishpig_Wordpress_Helper_Associations可以为您获取关联.

在这里你会发现这个功能;

public function getAssociations($type,$objectId,$storeId = null)

如果您单步浏览此文件,您将能够弄清楚您需要做什么,但为了方便起见,请在下面使用它的示例;

$_helper = Mage::helper('wordpress/associations');
$_category  = $this->getCurrentCategory();
$_associations = $_helper->getAssociations('category/category',$_category->getId());
$_collection = Mage::getResourceModel('wordpress/post_collection')
    ->addIsPublishedFilter();

这将返回一个数组,其中键是WP类别ID,值是它在Magento中的位置.

接下来,您需要将键翻转为值.

警告不要使用array_flip!如果您具有相同位置的类别,则仅保存具有相同值的最后一个oe.

解决方案它有点脏,但您可以循环并重建要在以后使用的数组;

if($_associations && $_collection->getSize()){
    $_wpIds = array();
    foreach($_associations as $_id => $_position){
        $_wpIds[] = $_id;
    }
}

您可以使用addCategoryIdFilter($categoryId)函数过滤集合.
不幸的是,它似乎不接受数组,如果它被多次应用到你的集合,那么它将返回false.遗憾的是,模块中似乎没有一个函数可以按类别ID数组过滤集合.

在理想的世界中,ID过滤器应接受字符串和数组,如果是数组,则应该能够定义AND / OR参数.可能是未来发布的东西;)

相关文章

文章浏览阅读8.4k次,点赞8次,收藏7次。SourceCodester Onl...
文章浏览阅读3.4k次,点赞46次,收藏51次。本文为大家介绍在...
文章浏览阅读1.1k次。- php是最优秀, 最原生的模板语言, 替代...
文章浏览阅读1.1k次,点赞18次,收藏15次。整理K8s网络相关笔...
文章浏览阅读1.2k次,点赞22次,收藏19次。此网络模型提供了...
文章浏览阅读1.1k次,点赞14次,收藏19次。当我们谈论网络安...