我猜它在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参数.可能是未来发布的东西;)