这已经在很多地方讨论过了,但是值得在这里分享:
方法1
转到主题的
app / design / frontend / base / default / template / catalog / product / view.phtml
找到以下代码,并进行注释
<?php //echo $this->getReviewsSummaryHtml($_product, false, true)?>
并替换为以下内容:
<?php echo $this->getReviewsSummaryHtml($_product, 'short')?>
在view .phtml文件中,“ $ this”指向/var/www/http/app/code/core/Mage/Catalog/Block/Product/View.php中的Mage_Catalog_Product_View类
$ _product是已为我们加载的产品对象,因此代码
$this->getReviewsSummaryHtml($_product, false, true)
works. But, if you want to show the above code in other pages, where product object is not loaded, please ensure you load the product
首先-如下
<?php
$productId = "1234";
$product = Mage::getModel('catalog/product')->load($productId);
echo $this->getReviewsSummaryHtml($product, 'short')
?>
请注意,我使用的是$ product而不是$ _product,这取决于您!
方法2
该方法实际上根据评论数和相应的评分显示星星
<?php
//reviews are based on store, so get store Id
$storeId = Mage::app()->getStore()->getId();
//now load the review of the product based on set store id
$ratingSummaryData = Mage::getModel('review/review_summary')
->setStoreId($storeId)
->load($_product->getId());
?>
<div class="ratings">
<p class="rating-title"><?php echo "Ratings :" ?></p>
<div class="rating-box">
<div class="rating"
style="width:<?php echo $ratingSummaryData['rating_summary']; ?>%">
</div>
</div>
<p class="rating-title">
<?php
//this shows like - 4.0 / 5.0 5 Review(s)
echo ( (5 / 100) * $ratingSummaryData->getRatingSummary()) .
' / 5.0 ' . $ratingSummaryData['reviews_count'] . ' Review(s)'
?> </p> </div>
希望它能帮助一些人。