I am trying to display a custom multiselect attribute as images on the frontend if they have been selected by the store admin.
So far I have been able to get the values "as text" on the frontend but I am not sure how I can go about associating each value with an image...
Here is what I have so far
<?php
$multiSelectArray = $this->getProduct ()->getAttributeText('suitable_for');
$lastItem = end ($multiSelectArray);
foreach ($multiSelectArray as $multiSelectItem) {
echo $multiSelectItem;
if ($multiSelectItem != $lastItem) echo ", ";
}
?>
The above code will show the values of the multiselect but I am stuck on how to associate the values with an image instead of text.
I anyone can assist I'd be very grateful!
1 Answer 1
Do this:
<?php
$multiSelectArray = $this->getProduct ()->getAttributeText('suitable_for');
$lastItem = end ($multiSelectArray);
foreach ($multiSelectArray as $multiSelectItem) :?>
<img src="/media/img/<?php echo $multiSelectItem ?>"></img>
<?php endforeach;
?>
and store your images in /media/img/[item].[ext], the same value as the text stored.
-
Nice approach. May be file extension (jpeg or similar) needed as well as basic file name validation.Amasty– Amasty2014年07月30日 20:53:16 +00:00Commented Jul 30, 2014 at 20:53
-
Fantastic!!! Thankyou so much, I really appreciate your help...user1704524– user17045242014年07月30日 20:53:39 +00:00Commented Jul 30, 2014 at 20:53
-
good one!!!!!!!Monty Nabeel– Monty Nabeel2018年11月11日 15:24:35 +00:00Commented Nov 11, 2018 at 15:24