我无法过滤掉posts.phtml块中与产品相关联的相关类别帖子(使用Fishpig)。我尝试使用以下解决方案来获取帖子:
Fishpig Wordpress Magento Post issue
像这样:$categoryId = Mage::registry('wordpress_category')->getId();
$recentPostCollection = Mage::getModel('wordpress/post')->getCollection()
->addIsPublishedFilter()
->addCategoryIdFilter($categoryId)
->setOrder('post_date', 'desc')
->setPageSize($numPostsToShow)
;
然后修改原始的相关帖子块:
<?php //$posts = $this->getPosts() ?>
<?php $posts = $recentPostCollection; ?>
<?php if (count($posts) > 0): ?>
<div class="block block-blog block-recent-posts">
<?php if ($title = $this->getTitle()): ?>
<div class="block-title">
<strong><span><?php echo $this->__($title) ?></span></strong>
</div>
<?php endif; ?>
<div class="block-content">
<ul id="<?php echo $this->getListId() ?>">
<?php foreach($posts as $post): ?>
<li class="item">
<?php $image = $post->getFeaturedImage(); ?>
<img src="<?php echo $this->htmlEscape( $image->getAvailableImage() ) ?>" ?>
</li>
<?php endforeach; ?>
</ul>
<script type="text/javascript">decorateList('<?php echo $this->getListId() ?>')</script>
</div>
</div>
<?php endif; ?>
而且,那是行不通的。当我将静态数字放入$ categoryID时,我至少可以将数据输入$ recentPostCollection,但循环不适用于该数据结构......任何帮助都会令人惊叹!感谢。
答案 0 :(得分:0)
magento fishpig related posts display by category:->
<?php $categories = $post->getTermCollection('category') ?>
<?php if (count($categories) > 0): ?>
<?php foreach($categories as $category): ?>
<?php $getCategory = $this->escapeHtml($category->getId()); ?>
<div id="inhouse-tab"><?php echo Mage::getSingleton('core/layout')->createBlock('wordpress/sidebar_widget_posts')->setTemplate('wordpress/sidebar/widget/categoryposts.phtml')->setCategoryId($getCategory)->setPostCount(4)->toHtml(); ?></div>
<?php break; ?>
<?php endforeach; ?>
<?php endif; ?>