2012-09-17 40 views
1

我創建了一個多選項屬性,以便爲每個選項顯示圖像,但我無法使其工作。屬性將圖像分配給每個多選項

我已經從這裏的另一篇文章中使用此代碼來獲取要顯示的選項列表。

我使用的代碼是:

<?php if($_product->getResource()->getAttribute('suitable_for')->getFrontend()->getValue($_product)): ?> 
     <h4>Suitable for:</h4> 
     <ul><li><?php 
      $_comma = ","; 
      $_list = "</li><li>"; 
      echo str_replace($_comma,$_list,$_product->getResource()->getAttribute('suitable_for')->getFrontend()->getValue($_product)) ?>  
     </li></ul> 
     <?php endif; ?> 

所以這個現在顯示的選項,對彼此頂部一個列表。

正如我所說我想要爲每個選項顯示圖像。

我認爲最好的辦法是有div和分配給每個div的圖像。

我希望我能得到的輸出是:

<div class="option1"></div> 
<div class="option2"></div> 
<div class="option3"></div> 
<div class="option3"></div> 

,而不是輸出,上面的代碼有:

<ul> 
    <li>option1</li> 
    <li>option2</li> 
    <li>option3</li> 
    <li>option4</li> 
</ul> 
+0

你只是問如何將輸出從無序列表更改爲一組DIV元素? – beeplogic

回答

1

更改您的代碼

<?php if($_product->getResource()->getAttribute('suitable_for')->getFrontend()->getValue($_product)): ?> 
    <h4>Suitable for:</h4> 
    <div class="<?php 
     $_comma = ","; 
     $_list = "\"></div><div class=\""; 
     echo str_replace($_comma,$_list,$_product->getResource()->getAttribute('suitable_for')->getFrontend()->getValue($_product)) ?>  
    </div> 
    <?php endif; ?> 
+0

好吧,我做了這個,它工作 - 我編輯上面的代碼,使其工作,因爲它不工作,但我現在有一個空間在我的div名稱前 - 任何想法? –

+0

結果(除了第一個div)是這樣的:

+0

好吧,現在它的工作原理,你還想要什麼?請清楚你做了什麼 - 即粘貼你的代碼,而不是告訴我你需要什麼,因爲你在第二條評論中打印的內容是你想看到的內容,據我所知......準確地說,我們可以提供幫助!謝謝 – serdarsenay