【问题标题】:limit number of product reveiws that display on product page magento限制显示在产品页面 magento 上的产品评论数量
【发布时间】:2012-09-28 20:02:33
【问题描述】:

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

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

更新:我尝试进行以下更改,但仍然无法正常工作 - 关于我做错了什么有什么想法吗?

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

<?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>

【问题讨论】:

    标签: php magento


    【解决方案1】:

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

    $collection->setPageSize('number of reviews on page');
    

    【讨论】:

    • 我会把它放在哪里?这就是项目的拉入方式:getReviewsCollection()->getItems();?> 这是我添加脚本以添加项目数量的同一行吗?
    • 是的,getReviewsCollection()->setPageSize('页面评论数')->getItems();?>
    • 如果您要向产品页面添加评论,您应该从评论模块添加块。插入块 处理并将 review/product/view/list.phtml 替换为您的模板
    • 我发现了这个:stackoverflow.com/questions/6042791/… 并且它起作用了,现在我只需要显示“5”而不是 1??
    • 还真的需要这个答案吗??有什么想法吗?
    【解决方案2】:

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

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

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

    【讨论】:

    • 我会说这是一个糟糕的解决方案,因为您正在向页面加载大量评论,然后只是限制显示的数量。非常低效。看@Cangzhou Wu的解决方案
    【解决方案3】:

    我不得不这样做并找到了一种更强大的方法。在您主题的 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>
    

    【讨论】:

      【解决方案4】:
      app\code\core\Mage\Review\Block\Product\View\List.php
      
       protected function _beforeToHtml()
      {
          $this->getReviewsCollection()->setPageSize(5)
              ->load()
              ->addRateVotes();
          return parent::_beforeToHtml();
      }
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-06-30
        • 1970-01-01
        • 1970-01-01
        • 2013-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多