【问题标题】:Displaying Category Image in navigation menu in magento在magento的导航菜单中显示类别图像
【发布时间】:2014-03-20 16:26:04
【问题描述】:

我是 magento 的新手,我需要一些帮助来显示类别中的图像, 我已经从我的 magento 后端上传了一个类别中的图像,我正试图像这样在导航栏中显示

<ul id="nav_category" class="nav_category">  
<?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php echo $this->drawItem($_category) ?> 
<?php echo Mage::getModel('catalog/category')->load($_category->getId())-     >getImageUrl()    ?>
<?php endforeach ?>
</ul>

但它不显示图片的 url,它只是显示来自 drawItem 函数的类别名称。

请帮忙

谢谢

【问题讨论】:

    标签: magento


    【解决方案1】:

    Vikash,试试下面的代码....

      <ul id="nav_category" class="nav_category">  
        <?php foreach ($this->getStoreCategories() as $_category): ?>
            <?php echo $this->drawItem($_category) ?> 
        <?php
            $_helper    = Mage::helper('catalog/output');
            $_imgHtml   = '';
            if ($_imgUrl = $_category->getImageUrl()) {
                $_imgHtml = '<img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$_category->getName().'" />';
                $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
            }
        ?>
        <?php if($_imgUrl): ?>
            <?php echo $_imgHtml ?>
        <?php endif; ?>
        <?php endforeach; ?>
        </ul>
    

    【讨论】:

      【解决方案2】:

      是的,您可以在 magento1.9 的顶部导航菜单中显示类别图像: 步骤:

      1. 加载类别对象:

        $category = Mage::getModel('catalog/category')->load('category-id'); 
        
      2. 然后调用getData()方法:

        $category->getData('image');  // It will return image url; 
        
      3. 然后添加媒体目录路径:

        Mage::getBaseUrl('media'); // returns megento media directory path.
        

      以下是我使用的示例代码。

      $splittedArray = explode($delimiter = 'category-node-', $child->getId());
      $category = Mage::getModel('catalog/category')->load(end($splittedArray));
      
      if (!empty($category->getData('image'))) {
          $html .= '<div> ';
          $html .= "<a href=" . $category->getURL() . " title =" . $category->getName() . ">";
          $html .= "<img src=" . Mage::getBaseUrl('media') . 'catalog/category/' . $category->getData('image') . " alt=" . $category->getName() . " >";
          $html .= "</a>";
          $html .= '</div>';
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多