How can I get the review count on review's list.phtml in Magento 1.8?

How can I get the review count on review's list.phtml in Magento 1.8?

September 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How can I get the review count on review's list.phtml in Magento 1.8?

Getting Review Count on Magento 1.8 List.phtml Page

In Magento 1.8, displaying review counts on the list.phtml page can be challenging due to version-specific changes in the core codebase. However, with proper object initialization and method calls, you can retrieve this information accurately.

Understanding the Error

The error you encountered is due to a missing getId() method call on an undefined variable or object. Let’s break down your initial code:

$storeId    = Mage::app()->getStore()->getId();

While this line should work in most cases, Magento 1.8 might have compatibility issues with the Mage::app() function when called before the page initialization has completed.

Correcting the Code

To resolve the error, you need to ensure that you’re accessing the store object within the appropriate context:

<?php
// Get the number of reviews of the product on the product page.
$storeId = Mage::app()->getStore()->getId();
$productId = $_product->getId();

Mage::init('default');

$summaryData = Mage::getModel('review/review_summary')
    ->setStoreId($storeId)
    ->load($productId);

/* @var $summaryData Mage_Review_Model_Review_Summary */
$reviewsCount = $summaryData['reviews_count'];
?>

In this corrected version:

  1. We ensure that Magento is initialized using Mage::init('default').
  2. We retrieve the product ID using $productId = $_product->getId();.
  3. The review summary model is loaded with the correct store ID and product ID.
  4. The reviews count is stored in a new variable named $reviewsCount.

Displaying Review Count

Now, you can display the review count directly in your list.phtml file:

<?php if (!empty($reviewsCount)): ?>
    <a href="#customer-reviews" class="nobr">
        <?php echo $this->__('%s Review(s)', $reviewsCount) ?>
    </a>
<?php endif; ?>

Explaining the Behavior in count.phtml

The reason why the count is always empty in your count.phtml file might be due to a timing issue or a different context in which the review objects are loaded. In most cases, the reviews count should be available within the product view context.

If you still face issues with the count.phtml file, consider using a custom observer to preload the reviews data before the product view template is rendered.

Conclusion

Retrieving the review count on the Magento 1.8 list.phtml page requires careful handling of object initialization and proper method calls. By following the corrected code snippet provided above, you should be able to display the review counts accurately within your product pages.

For more in-depth information about Magento development best practices and version compatibility, consider exploring our comprehensive guides at Laravel Company.

Magento 1 Catalog Themes Errors

Our network