I am successfully using this code to display a brand logo

php $brand=$_product->getAttributeText('brand');

echo '

'_',$brand).'.jpg" alt="'.$brand.'">'

now what i need help with is making it a link as well

the problem is where as

My brands have capital letters as my attribute does so for example Brand Punch It Performance uses image Punch_It_performance.jpg

however the url for it is


now forgive my newbieness to php here but i could really use some help modifying the above code snippet to function so when its clicked it goes to the proper page

  • Wouldnt let me post this code above <?php $brand=$_product->getAttributeText('brand'); echo '<img src="/skin/frontend/default/default/images/media/'.str_replace(' ', '_',$brand).'.jpg" alt="'.$brand.'">' ?> </div> – user3677211 Oct 3 '16 at 19:51

This should do it:

$brand = $_product->getAttributeText('brand');
$brandImage = str_replace(' ', '_', $brand) . ".jpg";
$brandLink = strtolower(str_replace(' ', '-', $brand)) . ".html";
$brandBaseUrl = Mage::getBaseUrl() . '/shop-by-brand/';
<a href="<?php echo $brandBaseUrl . $brandLink; ?>" title="<?php echo $brand; ?>">
    <img src="<?php echo $this->getSkinUrl("images/media/" . $brandImage); ?>" alt="<?php echo $brand; ?>" />

Edit1: fixed typo

  • getting a syntax error on this line – user3677211 Oct 3 '16 at 20:13
  • $brandLink = strtolower(str_replace(' ', '-', $brand) . ".html"; – user3677211 Oct 3 '16 at 20:14
  • I got this working <?php $brand=$_product->getAttributeText('brand'); echo strtolower('<a href="/'.str_replace(' ', '-',$brand).'.html" alt="'.$brand.'">') ; echo '<img src="/skin/frontend/default/default/images/media/'.str_replace(' ', '_',$brand).'.jpg" alt="'.$brand.'">' ?></a> – user3677211 Oct 3 '16 at 20:26
  • I updated my answer, that line was missing a character. – Vincent Hornikx Oct 4 '16 at 5:54
  • awesome thanks , now say i have another attribute "restrictions" with 2 options Off Road and Race Only i tried using the same code snippet to display a image named Off_Road.jpg and Race_Only.jpg but it come back blank maybe i didnt set up the new attribute correctly? – user3677211 Oct 4 '16 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.