加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 22:54:29 所属栏目:PHP教程 来源:网络整理
导读:我正在探索Magento的Fishpig扩展,并发现了一种有趣的方式来绑定博客文章博客类别为magento的类别.但是,我没有得到如何在magento类别页面的前端显示. 我猜它在Fishpig模块的内置功能. 我尝试使用以下代码: catalog_category_view reference name="left" bloc
我正在探索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参数.可能是未来发布的东西;)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读