3

On the homepage i have categories with description and 2 latest added products from that specific category.

Now i have it working to display 2 products per category with image and productname but i can't get it working to show the product price also.

This is my code now:

<?php
    $_categoryId = explode(' ', $category['id']);

    $count = 0;

    $_productCollection = Mage::getModel('catalog/category')->load($_categoryId)
        ->getProductCollection()
        ->addAttributeToSelect('*')
        ->setOrder('date_added', 'ASC');
    ?>

    <?php foreach ($_productCollection as $_product): ?>

        <?php
            $count++; // Note that first iteration is $count = 1 not 0 here.
            if($count <= 3) continue; // Skip the iteration unless 4th or above.
        ?>

        <li class="category-row-list-item">

            <a class="product-name" href="<?php echo $_product->getProductUrl() ?>">
                <?php echo $this->htmlEscape($_product->getName()) ?>
            </a>

        </li>
        <?php
            if($count == 6) break;
        ?>
    <?php endforeach ?>
1

Add this code for price where you want to display it.

echo Mage::helper('checkout')->formatPrice($_product->getFinalPrice());

1

Hello You can show price by below code

echo Mage::helper('core')->currency($_product->getPrice);

Hope this will help you

  • Thank you for your answer, i've used the first answer on this question – n00bly Aug 3 '16 at 14:14
0
<?php echo $this->getPriceHtml($_product, true) ?> 

for price rendering price in case if your template uses Mage_Catalog_Block_Product block

If not you can use

 <?php echo Mage::app()->getLayout()->createBlock('catalog/product')->getPriceHtml($_product); ?>

Hope it will help you.

  • Thank you for your answer but this one doesn't work in my case, i've tried but it stays blank :( – n00bly Aug 3 '16 at 14:13
0

kindly add price attribute to your collection.

$_productCollection->addAttributeToSelect('price'); 

and then add

$_product->getPrice();

for show price with out formatting, And if you want to show it with currently you need to add code

<?php echo Mage::helper('core')->currency($_product->getPrice(), true, false);?>
  • Thank you for your answer, i've used the first answer on this question – n00bly Aug 3 '16 at 14:14

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.