how to display thumbnail from category using getThumbnailUrl() in Magento

后端 未结 3 914
轮回少年
轮回少年 2021-01-24 07:03

I have bee trying to make this work but had no luck, Basically I need to display the main menu categories on the content block and I did, but now I need to display the thumbnail

3条回答
  •  猫巷女王i
    2021-01-24 07:56

    Here's my solution working on Magento 1.7.0.2

    Create sub-categories.phtml file

    Location: app/design/fronend/YOUR-THEME/default/template/catalog/navigation/sub-categories.phtml  
    

    Take note of where to pull thumbnail images from. You will need to add an absolute path of your website at www.yourwebsitenamehere.com below.

    sub-categories.phtml file contents:

    getCurrentCategory() ?> getCurrentChildCategories() ?> count()): ?> getIsActive()): $cur_category = Mage::getModel('catalog/category')->load($_category->getId()); $layer = Mage::getSingleton('catalog/layer'); $layer->setCurrentCategory($cur_category); $catName = $this->getCurrentCategory()->getName(); if($_imageUrl = !$this->getCurrentCategory()->getThumbnailImageUrl()): ?> getCurrentCategory()->getThumbnailImageUrl()): ?> setCurrentCategory($_maincategorylisting); ?>

    Create a static block.
    1. Block Title: Sub Category Listing
    2. Identifier: sub-categories
    3. Content: {{block type="catalog/navigation" template="catalog/navigation/sub-categories.phtml"}}

    Create Category.php file
    Copy app/code/core/Mage/Catalog/Model/Category.php to app/code/local/Mage/Catalog/Model/Category.php. Once copied, edit file.

    Once inside file, look near line 491. Find:

    public function getImageUrl()
    {
        $url = false;
        if ($image = $this->getImage()) {
            $url = Mage::getBaseUrl('media').'catalog/category/'.$image;
        }
        return $url;
    }
    

    After this paste in:

    /**
     * Retrieve thumbnail image URL
     *
     * @return string
     */
    public function getThumbnailImageUrl($fullpath = false)
    {
    
      $url = false;
    
      if ($image = $this->getThumbnail()) {
    
          if ($fullpath == true) {
              $url = Mage::getBaseUrl('media').'catalog/category/'.$image;
          } else {
              $url = $image;
         }
      }
    
      return $url;
    
    }
    

    Backend Magento.
    1. Select Catalog > Manage Categories.
    2. Create or edit the main category that will display thumbnails from sub categories.
    3. Under Display Settings Tab
    4. Display mode: Static block only
    5. CMS Block: Sub Category Listing
    6. Is Anchor: No
    7. Thumbnail Image: Choose your file

    If you do not see your edits make sure to flush your Magento cache.

提交回复
热议问题