0

我无法过滤掉与posts.phtml 块中的产品相关的相关类别帖子(使用Fishpig)。我尝试使用以下解决方案来获取帖子:

Fishpig Wordpress Magento 发布问题

像这样:

$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,但循环不适用于该数据结构......任何帮助都会很棒!谢谢。

4

1 回答 1

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; ?>
于 2016-08-27T08:28:01.947 回答