1

I have custom attribute called slider_link and trying to display it's value in home/index/cms page. I use the following code:

<?php echo $_product->getData("slider_link"); ?>

After adding this, my index page dose not load.

However, I had used above code on my view.phtml and list.phtml with no errors. everything is working fine.

Any idea how can I get the attribute value of my custom attribute called slider_link on my home page?

UPDATED

<div class="flexslider">
    <ul class="slides">
    <?php 
    $products = Mage::getModel('catalog/product')->getCollection();
    $products->joinField(
    'qty', 
    'cataloginventory/stock_item', 
    'qty', 
    'product_id=entity_id', 
    '{{table}}.stock_id=1', 
    'left' 
    );
    $products->addAttributeToSelect(array('name', 'thumbnail', 'price', 'special_price' , 'RegularPrice' )); //ovdje idu atributi
    $products->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id=entity_id', null, 'left' );
    $products->getSelect()->limit(5);
    $products->getSelect()->order('RAND()'); // random sortiranje
    $products->addAttributeToFilter('category_id', array('in' => array(21))); // ubacujem kategorije id
    $this->_reviewsHelperBlock = $this->getLayout()->createBlock('review/helper'); // pozivanje review helper, da bi se prikazao review summary
    foreach ($products as $product)  : 
    ?> 
        <li>
            <a href="<?php echo $_product->getAttributeText("slider_link"); ?>"><img class="thumbnail" src="<?php echo Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(780, 395)?>" alt="<?php echo $product->getName()?>"></a>
        </li>
    <?php endforeach; ?>
    </ul>
</div>
  • What code are your using on your homepage (I need to know the block type and template)? – Manashvi Birla Jul 23 '15 at 10:15
  • i just updated the post – user15151 Jul 23 '15 at 10:16
1

You are calling this

<?php echo $_product->getData("slider_link"); ?>

but the variable $_product does not exist.
you loop looks like this:

foreach ($products as $product)  :

So you should use echo $product->getData("slider_link") with no underscore for the product variable.

Also, you should add the attribute slider_link to the collection.
This

$products->addAttributeToSelect(array('name', 'thumbnail', 'price', 'special_price' , 'RegularPrice' )); //ovdje idu atributi

should be

$products->addAttributeToSelect(array('name', 'thumbnail', 'price', 'special_price' , 'RegularPrice', 'slider_link' )); //ovdje idu atributi
  • tnx bro for clearing this up for me – user15151 Jul 23 '15 at 10:59
1

You are using $_product->getAttributeText("slider_link") to get the attribute value, but the product collection is loaded with $product so use this

$product->getAttributeText("slider_link");

 

foreach ($products as $product)  : 
    ?> 
        <li>
             <a href="<?php echo $product->getAttributeText("slider_link"); ?>"><img class="thumbnail" src="<?php echo Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(780, 395)?>" alt="<?php echo $product->getName()?>">
              </a>
         </li>
    <?php endforeach; ?>
                    </ul>
                </div>

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.