Php 限制产品页面magento上显示的产品展示数量
因此,我已经了解了如何在产品页面上显示产品评论。现在我需要了解如何限制显示的评论数量,并将“阅读更多评论”链接添加到产品评论默认页面 有什么想法吗?或者有人能给我指出正确的方向吗?我尝试了很多不同的脚本,但都没有成功 更新:我试着做了下面的更改,但仍然不起作用-有没有关于我做错了什么的想法 是的,这就是我的想法,但它仍然不起作用,有没有想法我做错了什么Php 限制产品页面magento上显示的产品展示数量,php,magento,Php,Magento,因此,我已经了解了如何在产品页面上显示产品评论。现在我需要了解如何限制显示的评论数量,并将“阅读更多评论”链接添加到产品评论默认页面 有什么想法吗?或者有人能给我指出正确的方向吗?我尝试了很多不同的脚本,但都没有成功 更新:我试着做了下面的更改,但仍然不起作用-有没有关于我做错了什么的想法 是的,这就是我的想法,但它仍然不起作用,有没有想法我做错了什么 <?php $_items = $this->getReviewsCollection()->setPageSize('5')
<?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>
我希望您使用集合获取评论。所以你可以
$collection->setPageSize('number of reviews on page');
这就是我最终采用的解决方案:
<?php
$i = 1;
foreach ($_items as $_review):
if ($i < 6): ?>
感谢所有试图帮助我的人……我不得不这么做,并找到了一种更有效的方法。在主题的review.xml
文件中,找到创建寻呼机的这一行:
<block type="page/html_pager" name="product_review_list.toolbar" />
并将其替换为以下数字(除您喜欢的数字外):
6.
这对我有用。当然,您应该重写块我应该把它放在哪里?这就是项目的导入方式:这是我添加脚本以添加项目数量的同一行吗?是的,如果要向产品页面添加评论,则应添加来自评论模块的块。在句柄中插入块和,并将review/product/view/list.phtml替换到模板中我发现:它成功了,现在我只需要显示“5”而不是1??仍然需要一个答案??有什么想法吗?我认为这是一个糟糕的解决方案,因为你在页面上加载了大量的评论,然后限制了显示的数量。效率很低。请看@沧州吴的解答
<block type="page/html_pager" name="product_review_list.toolbar">
<action method="setLimit"><limit>6</limit></action>
</block>
app\code\core\Mage\Review\Block\Product\View\List.php
protected function _beforeToHtml()
{
$this->getReviewsCollection()->setPageSize(5)
->load()
->addRateVotes();
return parent::_beforeToHtml();
}