2013-03-07 76 views
2

我试图将我的主页上某个类别的产品数量限制为4个。限制在主页上显示的产品数量,list.phtml

我试图用这样做的代码是:

{{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): ?> 

任何想法上无论是在块内或限制的产品模板文件?

回答

4

越快是is_homepage=1

取代column_count=4,并在PHTML补充一点:

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

在此之前:

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

那么你将不得不在主页上只有1行(如果按我的设想排4)共4个产品

2

当我面临这个问题他们,我搜到很多网站,但有非常少的网站,让我明白的它.. 我自己编辑它自己做这些步骤显示固定数量的产品从某些类别如下: - 去

1) app\design\frontend\default\<your theme>\template\catalog\product 
    copy list.phtml and save as list_new.phtml 

现在打开list_new.phtml和搜索'结束后,如果循环插入此代码

<?php if($i<=4): // for 4 product?> 

和封闭式名单后。

<?php endif // for 4 product?> 

的代码看起来像这个 -

<?php if ($i++%$_columnCount==0): ?> 
    <ul class="products-grid"> 
<?php endif ?> 
<?php if($i<=4): // for 4 product?> 
    <li class="item<?php if(($i-1)%$_columnCount==0): ?>"> 
     // some code here 
    </li> 
<?php endif // for 4 product?> 

2)现在去的CMS>页>选择主页>内容>这里复制此代码(更改categy ID)

{{block type="catalog/product_list" name="product_list" category_id="<category id>" column_count="4"mode="grid" template="catalog/product/list_new.phtml"}} 
0

试试这个: $_productCollection=$this->getLoadedProductCollection(); $_productCollection->getSelect()->limit(5);

1

在Magento版本。 1.9.0.1 我找到了一个简单的解决方案,只需在list.phtml 中添加这些行,只需找到两次foreach循环,因此需要在两个位置添加。

<?php $i=0; ?> 
<?php foreach ($_productCollection as $_product): 
if($i == 6) break; 
$i++; 
?> 

我把它记录为6条记录,您可以根据需要更改它。

谢谢

相关问题