2012-10-30 111 views
1

我有蜜蜂試圖使這項工作,但沒有運氣,基本上我需要顯示內容塊上的主菜單類別,我做了,但現在我需要在內容塊內顯示類別名稱旁邊的縮略圖分類。我創建的應用程序/德興/ fronend /默認/主題/模板/目錄/導航/ category_listing.php,看起來像內一個新的自定義模塊:如何使用Magento中的getThumbnailUrl()從類別中顯示縮略圖

<div class="box layered-nav"> 
    <div class="head"> 
    </div> 
    <div class="border-creator"> 
     <div class="narrow-by"> 
      <dl id="narrow-by-list"> 

     <dd> 
     <ol>   
     <?php foreach ($this->getStoreCategories() as $_category): ?> 
      <dt> 
      <a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="active"<?php endif ?>><?php echo $this->htmlEscape($_category->getName()) ?> 
      <img src="<?php echo $_category->getThumbnailUrl() ?>" width="100" height="100" style="background:red; height: 100px; width: 100px; display: block" alt="<?php echo $this->htmlEscape($_category->getName()) ?>" /> 
      </a> 

      </dt> 
     <?php endforeach ?> 

     </ol> 
     </dd> 
     </dl><script type="text/javascript">decorateDataList('narrow-by-list')</script> 
    </div> 
    </div> 
</div> 

然後我加入到這個應用程序/代碼/核心/法師/目錄/型號/ Categorie.php

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

任何想法,爲什麼不拉和顯示圖像?我已經添加到使用管理面板的類別,清除緩存並刷新數據,任何想法?

Magento and Firebug

回答

5

使用此以下函數來顯示類別的縮略圖圖像

public function getThumbnailImageUrl() 
    { 
     $url = false; 

     if ($image = $this->getThumbnail()) { 

     $url = Mage::getBaseUrl('media').'catalog/category/'.$image; 
     } 
     return $url; 
    } 

然後,使用任何類別:

$ _imageUrl = $這 - > getCurrentCategory() - > getThumbnailImageUrl( )

你可以得到縮略圖圖像。

請參閱本文 http://www.douglasradburn.co.uk/getting-category-thumbnail-images-with-magento/

0

這裏的工作對Magento的1.7.0.2我的解決方案

創建子文件categories.phtml

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

採取記下拉縮略圖從。您需要在下面的www.yourwebsitenamehere.com處添加您網站的絕對路徑。

子categories.phtml文件的內容:

<div id="categories"> 
    <?php $_maincategorylisting = $this->getCurrentCategory() ?> 
    <?php $_categories = $this->getCurrentChildCategories() ?> 
    <?php if($_categories->count()): ?> 
    <? foreach($_categories as $_category): ?> 
     <? if($_category->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()): 
       ?> 
       <?php /* Default subcategory jpg if no image exists */ ?> 
       <div class="category-box"> 
       <div class="category-image-box"> 
        <a href="<?php echo $this->getCategoryUrl($_category) ?>"> 
         <img src="<?php echo $this->getSkinUrl('images/subcategory-default.jpg') ?>"> 
        </a> 
       </div> 
       <div> 
        <p> 
         <a href="<?php echo $this->getCategoryUrl($_category) ?>"> <?php echo $catName ?></a> 
        </p> 
       </div> 
       </div> 
      <? endif ?> 
      <? if($_imageUrl = $this->getCurrentCategory()->getThumbnailImageUrl()): ?> 
      <?php /* Displays the subcategory image */ ?> 
      <div class="category-box"> 
       <div class="category-image-box"> 

       <a href="<?php echo $this->getCategoryUrl($_category) ?>"> 
        <img src="http://www.yourwebsitenamehere.com/media/catalog/category/<?php echo $_imageUrl ?>"> 
       </a> 
       </div> 
       <div> 
       <p> 
        <a href="<?php echo $this->getCategoryUrl($_category) ?>"> <?php echo $_category->getName() ?></a> 
       </p> 
       </div> 
      </div> 
     <? endif; endif; ?> 
    <? endforeach ?> 
    <?php $layer->setCurrentCategory($_maincategorylisting); ?> 
    <? endif; ?> 
</div> 

創建靜態塊。
1塊標題:子類別清單
2.標識:子類別
3.內容:{{block type="catalog/navigation" template="catalog/navigation/sub-categories.phtml"}}

創建Category.php文件
複製app/code/core/Mage/Catalog/Model/Category.phpapp/code/local/Mage/Catalog/Model/Category.php。一旦被複制,編輯文件。

一旦裏面的文件,看近線491查找:

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

這個貼在後:

/** 
* 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; 

} 

後端Magento的。
1.選擇目錄>管理類別。
2。創建或編輯將顯示子類別縮略圖的主類別。
3.在顯示設置選項卡
4.顯示方式:靜態塊只
5. CMS塊:子類別清單
6.是否錨:沒有
7.縮略圖:選擇你的文件

如果你沒有看到你的編輯,請確保刷新你的Magento緩存。

0

無需改變應用程序/代碼/本地/法師/目錄/型號/ Category.php

可以通過這些行代碼很容易做到......試試這個...它的工作原理

$child= Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId(); 

$imageSrc = Mage::getModel('catalog/category')->load($child)->getThumbnail(); 

$ThumbnailUrl = Mage::getBaseUrl('media').'catalog/category/'.$imageSrc; 

echo "<img src='{$ThumbnailUrl}' />"; 
相關問題