2009-11-17 39 views
0

是否可以將您在常規信息選項卡中設置的主類別圖像製作爲鏈接?將類別圖像鏈接到

它呈現出來的:

<img src="http://www.example.com/media/catalog/category/example.jpg" alt="Example" title="Example" class="category-image" /> 

也許有一些擴展做到這一點?它只是不適合有一個不可點擊的主要橫幅...

+0

它應該鏈接到什麼? – 2009-11-17 14:49:37

回答

0

你想鏈接到同一類別或其他網頁?你可以試試這個技巧...

類別的圖像都是通過調用

<p><?php echo $_imgHtml?></p> 
模板\目錄\類\ view.phtml文件

加載。

您可以進行以下更改並硬編碼鏈接或使用動態鏈接。

<p><a href="#"><?php echo $_imgHtml?></a></p> 

如果要將其鏈接到當前類別,可以將當前類別URL函數分配給$變量並將其用作鏈接。

$_category->getUrl() 

如果您有特定要求,請在答案上留言。

3

沒有一套答案,但這裏是我們如何能夠做到在Magento 1.7.0.2:

在文件app /設計/前端/基/默認/模板/目錄/分類/ view.phtml有這些行添加圖像:

if ($_imgUrl = $_category->getImageUrl()) { 
    $_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this- >htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /> </p>'; 
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image'); 
} 

這基本上說:如果有圖像 - 創建必要的HTML來顯示它。

您可以重新創建這些相同的線,並添加一個if語句:

if ($_imgUrl = $_category->getImageUrl()) { 
//Add this, which reads: if the following text exists in the file name of the category image then create html with a link for that specific text 
    if(substr($_imgUrl,-20)=="some-systematic-identification-text"){ 
     $_imgHtml = '<p class="category-image"><a href="http://www.MY_SITE_URL.com" target="_blank"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></a></p>'; 
    } 
//Add this to check for more text 
    else if(substr($_imgUrl,-20)=="some-OTHER-systematic-identification-text"){ 
     $_imgHtml = '<p class="category-image"><a href="http://www.MY_SITE_URL.com" target="_blank"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></a></p>'; 
    } 
//Otherwise - just add the standard html that was there before we made changes 
    else{$_imgHtml = '<p class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></p>';} 
//Part of if-category image - if statement   
    $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image'); 
    } 

您可以複製和粘貼這些線在4我把這個帖子頂,然後根據需要修改,以確定何時您的文件名稱已顯示爲類別圖像,並創建點擊時彈出的相應鏈接。

1

假設你想要子類圖像和那個類別的產品,那麼你可以使用下面的代碼。

<a href="<?php echo $subcat->getUrlPath();?>"><img src="<?php echo Mage::getBaseUrl()."media/catalog/category/".$subcat->getThumbnail() ?>"/></a>