2012-10-25 77 views
4

我有一個現在正在構建的magento項目的概念。我的產品頁面下方有一個主要圖像(可配置產品)和縮略圖。我已經將我的代碼添加到了單擊縮略圖將圖像添加到主圖像區域的階段,但是我需要href作爲它包含的鏈接以附加到該imgs url。希望這是有道理的,任何幫助歡迎。更新magento產品頁面上的主要產品頁面

<?php 
    $_product = $this->getProduct(); 
    $_helper = $this->helper('catalog/output'); 
?> 

<div class="grid_12 grid_spacer_bottom"> 
<?php 
    $_img = '<img id="image" class="img-left img-inlineblock responsive-img" src="'.$this->helper('catalog/image')->init($_product, 'image').'" alt="'.$this->htmlEscape($this->getImageLabel()).'" />'; 
    //echo $_helper->productAttribute($_product, $_img, 'image'); 
?> 

<a href=""><?php echo $_helper->productAttribute($_product, $_img, 'image'); ?></a> 

</div> 

<div class="clear"></div> 

<?php if (count($this->getGalleryImages()) > 0): ?> 
<div class="more-views"> 
    <?php foreach ($this->getGalleryImages() as $_image): ?> 
     <div class="grid_4 grid_spacer_bottom"> 
      <a href="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'image', $_image->getFile()); ?>" title="<?php echo $_product->getName();?>" onclick="$('image').src = this.href; return false;"> 
       <img class="img-left img-inlineblock responsive-img" src="<?php echo $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail', $_image->getFile()); ?>" alt="<?php echo $this->htmlEscape($_image->getLabel()) ?>" /> 
      </a> 
     </div> 
    <?php endforeach; ?> 
</div> 
<?php endif; ?> 
+0

我認爲我稍微進步了,上更新顯示爲主要圖像IMG(在​​一個周圍的縮略圖)我嘗試添加一些JS更多的js也更新$ image的href並更新構建$ image的代碼......儘管如此,它仍然不會追加imgs url。 onclick =「$('image')。src = this.href; return false; $('image')。href = this.href; return false;」 –

回答

2

我假設你是嘗試,當你在大圖片上點擊它會縮略圖

的URL給這個HREF

<a href="" id="img_href"><?php echo $_helper->productAttribute($_product, $_img, 'image'); ?></a> 

你使用jQuery或ID,使原型(如果默認的Magento那麼這個)

原型

$('img_href').setAttribute('href', this.href); 
//$('img_href').href = this.href; // or 

的jQuery

$("#img_href").attr("href", this.href); 

普通的JavaScript

的document.getElementById( 'img_href')HREF = this.href。

更新縮略圖的onclick

onclick="$('image').src = this.href; $('img_href').setAttribute('href', this.href); return false;" 
+0

你的傳奇!我知道我非常親近,並意識到這是幾分鐘前onclick功能所需要的。 非常感謝您的幫助。 –

0

$('image')。parentNode.href ='your url';