Warning: Cannot modify header information - headers already sent by (output started at /www/wwwroot/sbboke.com/wp-content/plugins/wordpress-seo/src/integrations/front-end-integration.php:409) in /www/wwwroot/sbboke.com/wp-content/themes/pacify/content-single.php on line 5

Magento 获得产品评级明星

这已经在很多地方讨论过了,但是值得在这里分享:

方法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>

希望它能帮助一些人。

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论