简体   繁体   English

如何在Magento 1.8中获取评论的list.phtml的评论数?

[英]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? 如何获得评论的list.phtml的评论数?

frontend\base\default\template\review/product/view/list.phtml

I get an error when I use this code in this page, 在此页面中使用此代码时出现错误,

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

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

/* @var $summaryData Mage_Review_Model_Review_Summary */

/*

array(
['primary_id'] => 147
['entity_pk_value'] => 166
['entity_type'] => 1
['reviews_count'] => 1
['rating_summary'] => 80
['store_id'] => 1
)
*/
//var_dump($summaryData['reviews_count']);
?>

error, 错误,

Fatal error: Call to a member function getId() on a non-object in 

While the count on frontend\\base\\default\\template\\review/product/view/count.phtml will always return empty 虽然frontend\\base\\default\\template\\review/product/view/count.phtml上的计数将始终返回

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

Any idea why? 知道为什么吗?

I have code in my catalog.xml's <catalog_product_view translate="label"> , 我的catalog.xml的<catalog_product_view translate="label">有代码,

           <!-- adding review to the product page -->
            <block type="page/html_pager" name="product_review_list.toolbar">
                <action method="setLimit"><limit>2</limit></action>
            </block>
            <block type="review/product_view_list" name="product.info.product_additional_data" as="product_review" template="review/product/view/list.phtml">
                <block type="core/template" name="product_review_list.count" template="review/product/view/count.phtml" />
                <block type="review/form" name="product.review.form" as="review_form"/>
            </block>
            <!-- adding review to the product page -->

Please try very simple code It's work for me. 请尝试非常简单的代码,这对我来说很有效。

?php echo $this->getReviewsSummaryHtml($_product, 'short')?>

It's look like attached screenshot. 看起来就像所附的屏幕截图。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM