【问题标题】:Display all the Post Categories in Magento Fishpig在 Magento Fishpig 中显示所有帖子类别
【发布时间】:2016-03-29 18:55:18
【问题描述】:

我有两个具有两种不同布局的帖子类别,但现在两者都显示在同一个 view.phtml 中。我需要检查帖子所属的类别并相应地显示样式。

通过使用下面的方法,我可以加载 ID 为 2 的单个类别。

<?php $test = Mage::getModel('wordpress/term')->load(2);?>

有没有办法加载所有的帖子类别?

【问题讨论】:

    标签: magento fishpig


    【解决方案1】:

    Shyam 快到了。这是代码的稍微干净的版本:

    <?php $categories = $post->getTermCollection('category') ?>
    <?php if (count($categories) > 0): ?>
        <?php foreach($categories as $category): ?>
            <?php if ((int)$category->getId() === 1): ?>
                // Category ID #1
            <?php elseif ((int)$category->getId() === 2): ?>
                // Category ID #2       
            <?php else: ?>
                // All other categories
            <?php endif; ?>
        <?php endforeach; ?>
    <?php endif; ?>
    

    【讨论】:

      【解决方案2】:

      通过这种方法,您可以根据类别拆分帖子并以不同的布局显示在同一个view.phtml中,添加不同的布局将您的代码粘贴到if($getCategory == cat_id)部分中,如下所述。

          <?php $categories = $post->getTermCollection('category') ?>
          <?php if (count($categories) > 0): ?>
          <?php foreach($categories as $category): ?>
          <?php
           $getCategory = $this->escapeHtml($category->getId());
                  echo "Get cat: ".$getCategory;
          if($getCategory == 2)
           {
             //your code here
           }
          if($getCategory == 3)
               {
                 //your code here
               }
      <?php endforeach; ?>
      <?php endif; ?>
      

      【讨论】:

        猜你喜欢
        • 2013-12-06
        • 2015-02-14
        • 1970-01-01
        • 1970-01-01
        • 2014-05-13
        • 1970-01-01
        • 2017-06-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多