加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

magento – 限制主页上显示的产品数量,list.phtml

发布时间:2020-12-13 22:05:14 所属栏目:PHP教程 来源:网络整理
导读:我想在我的主页上将某个类别的产品数量限制为4个. 我试图这样做的代码是: {{block type="catalog/product_list" column_count="4" category_id="13" template="catalog/product/list.phtml"}} 以下是我尝试过的一些事情: num_products="4"limit = 4,limit=
我想在我的主页上将某个类别的产品数量限制为4个.

我试图这样做的代码是:

{{block type="catalog/product_list" column_count="4" category_id="13" template="catalog/product/list.phtml"}}

以下是我尝试过的一些事情:

num_products="4"
limit = 4,limit="4"
count = 4,count="4"
_productCollection="4"
_productsCount="4"

我已经制作了list.phtml的副本,认为可能有一种方法可以在那里进行更改,但无法找到方法.

在顶部pf list.phtml是这段代码:

<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>

在网格视图下有这样的:

<?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>

有关在块或模板文件中限制产品的任何想法?

解决方法

更快的是用is_homepage = 1替换column_count = 4

并在phtml中添加:

<?php if($this->getIsHomepage() && $i==4) break; ?>

在这之前 :

<?php if ($i++%$_columnCount==0): ?>

然后你将在主页上只有一行(如果我想的话是4行),所以总共有4个产品

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读