1

所以我想出了如何在产品页面上显示产品评论。现在我需要了解如何限制显示的评论数量并将“阅读更多评论”链接添加到产品评论默认页面。

有任何想法吗?或者谁能​​指出我正确的方向?我尝试了许多不同的脚本,但都没有运气。

更新:我尝试在下面进行更改,但仍然无法正常工作 - 关于我做错了什么的任何想法?

是的,这就是我的想法,但它仍然无法正常工作,任何想法我做错了什么?

<?php $_items = $this->getReviewsCollection()->setPageSize('5')->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<div class="box-title">
    <h2><?php echo $this->__('Customer<br><span id="smallH2">Reviews</span>') ?></h2>
</div>
<?php echo $this->getChildHtml('toolbar') ?>
<dl class="box-content" id="product-reviews-list">
<?php foreach ($_items as $_review):?>
<dt>
<?php
$reviewURL = $this->getReviewUrl($_review->getId());
$reviewURL = str_replace("catalog","review",$reviewURL);
?>
<a href="<?php echo $reviewURL ?>"><?php echo $this->htmlEscape($_review->getTitle())            ?></a>       <?php echo $this->__('Review by <span>%s</span>', $this->htmlEscape($_review->getNickname())) ?>
</dt> 
    <dd>
        <table class="data-table review-summary-table">
            <col />
            <col />
            <tbody>
                <?php foreach ($_review->getRatingVotes() as $_vote): ?>
                <tr>
                    <th class="label"><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
                    <td class="value">
                        <div class="rating-box">
                            <div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;">    
</div>
                        </div>
                    </td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <p><?php echo nl2br($this->htmlEscape($_review->getDetail())) ?></p>
        <p class="date"><?php echo $this->__('(Posted on %s)',    $this->formatDate($_review->getCreatedAt()), 'long') ?></p>
    </dd>
<?php endforeach; ?>
</dl>
<script type="text/javascript">decorateGeneric($$('#product-reviews-list dd'), ['last']);</script>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>
4

4 回答 4

1

这是我最终采用的解决方案:

<?php
$i = 1;
foreach ($_items as $_review):
    if ($i < 6): ?>

感谢所有试图提供帮助的人...

于 2012-11-21T15:30:05.123 回答
1

我不得不这样做并找到了一种更强大的方法。在您的主题review.xml文件中找到创建寻呼机的这一行:

<block type="page/html_pager" name="product_review_list.toolbar" />

并将其替换为以下内容(您喜欢的数字除外):

<block type="page/html_pager" name="product_review_list.toolbar">
    <action method="setLimit"><limit>6</limit></action>
</block>
于 2013-11-21T17:04:33.373 回答
1
app\code\core\Mage\Review\Block\Product\View\List.php

 protected function _beforeToHtml()
{
    $this->getReviewsCollection()->setPageSize(5)
        ->load()
        ->addRateVotes();
    return parent::_beforeToHtml();
}

它对我有用。当然,你应该重写块

于 2017-01-09T01:35:32.100 回答
0

我希望您使用集合来获取评论。所以你可以使

$collection->setPageSize('number of reviews on page');
于 2012-10-08T16:13:51.367 回答