【问题标题】:How to display associated WordPress category's posts on Magento product page (Fishpig integration)?如何在 Magento 产品页面(Fishpig 集成)上显示相关 WordPress 类别的帖子?
【发布时间】:2016-08-27 16:28:01
【问题描述】:

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

【问题讨论】:

    标签: wordpress magento fishpig


    【解决方案1】:
    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; ?>
    

    【讨论】:

      猜你喜欢
      • 2014-05-13
      • 2015-05-15
      • 2013-12-06
      • 2012-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多