So I am trying to create an option where I can select yes or no in the backend, and when it's set to yes, it adds an product overlay image with a 'new' tag. Here's what I have so far:

  1. Created an attribute called new and made sure it's set to Visible on Product View Page and Used in Product Listing. Both set to yes.

  2. Then I added this to my list.phtml file:

    <?php $_collectionSize = $_productCollection->count() ?>
      <?php $_columnCount = $this->getColumnCount(); ?>
         <ul class="products-grid products-grid--max-<?php echo $_columnCount; ?>-col">
        <?php $i=0; foreach ($_productCollection as $_product): ?>
            <?php /*if ($i++%$_columnCount==0): ?>
            <?php endif*/ ?>
            <!--beginning product labels--->
               <?php if ($_product->getAttributeText('new') == "Yes"): ?>
                 <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('new')->toHtml() ?>
                  <?php endif; ?>
            <!--end product labels-->
        <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
  3. Then I created a static cms block called 'new' and added a div with a tiny 'new' label image to that. As follows:

    <div class="new"><img src="{{media url="wysiwyg/new-label.png"}}" alt="" /></div>

So now I'm able to select yes or no in my backend with the products, and that works perfectly. However, the actual image is not showing up as an overlay on the products where I selected 'yes'.

What's missing?

2 Answers 2


Sounds good.

Make sure everything works as expected:

  1. Attribute is saved and loaded with the correct value Yes
  2. The if block is called in the list.phtml
  3. The <img> tag is filled with an image
  • Thanks Fabian, I've done all of the above and it still doesn't seem to work properly
    – magin
    Commented May 22, 2015 at 7:18
  • WHAT doesn't work? Somewhere it breaks, where? Commented May 22, 2015 at 8:52

You can actually achieve this by adding a cms block with one image, add this code anywhere it is suitable to show in the following file location:


<?php $_product = Mage::getSingleton('catalog/product')

if ($_product->getAttributeText('code') == "Yes"): ?>

<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('your-cms-static-block-code')->toHtml(); ?>

<?php endif; ?>

Replace 'code' with your newly created attribute code and 'your-cms-static-block-code' with your cms block identifier code. Also remember to add an overlay image in the cms block.

<img src="your-image-url.jpg" />

Let me know if you have any issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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