gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-10-31 23:40:02 25 4
gpt4 key购买 nike

我正在探索 Magento's Fishpig extension并找到了一种将博客文章和博客类别绑定(bind)到 magento 类别的有趣方法。但是,我不知道如何在 magento 类别页面的前端显示。

我猜它是 Fishpig module 的内置功能.

我尝试使用以下代码:

<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 参数。可能是 future 版本的东西 ;)

关于php - 使用 fishpig 在 magento 类别页面上显示相关的博客文章/博客类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28189044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com