首页>Magento>source

我创建了一个cms页面,在这个页面中我添加了以下代码:

{{block type="catalog/product_list" name="home.catalog.product.list" alias="products_homepage" template="catalog/product/view/products.phtml"}}

products.phtml

<?php
        $_productCollection = Mage::getModel('catalog/product')->getCollection()
                            ->setPageSize(20)
                            ->setCurPage(1);


    $_helper = $this->helper('catalog/output');
    if(Mage::registry('current_category')) {
    $_parent_id = Mage::registry('current_category')->getParentCategory()->getId();
    }
    $_itemCollection = Mage::helper('wishlist')->getWishlistItemCollection();
    if($_itemCollection) {
    foreach($_itemCollection as $wish) {
        $wish_product = $wish->getProduct();
        $wishlist_array[$wish_product->getId()] = $wish_product->getId();
    }
    }

?>
<?php if(!$_productCollection->count()): ?>
<div class="alert-error fade in" style="<?php if($_parent_id == 17) echo 'display:none';?>">
  <a class="close" data-dismiss="alert"><img style="width:24px;height:24px;margin-left:10px" src="<?php echo $this->getSkinUrl('images/Items.png'); ?>"></a>
  <?php echo $this->__('There are no products matching the selection.') ?>
</div>
<?php else: ?>
<div class="category-products">
    <div class="page-title" >
    <?php 
        //$_product = $this->getProduct();
    if(Mage::registry('current_category')) {
            $_parent=Mage::registry('current_category')->getParentCategory()->getName();
            if ($_parent != 'Main'):
              echo $_parent;
              echo ' > ';
          endif;
            $_category=Mage::registry('current_category')->getName();
            echo $_category; 
          }
    ?>
    </div>
    <?php echo $this->getToolbarHtml() ?>
    <?php // List mode ?>
    <?php // Grid Mode ?>
    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = 3; ?>
            <ul class="products-grid unstyled thubmnails row-fluid">
    <?php $i=0; foreach ($_productCollection as $pro): ?>
    <?php $_product = Mage::getModel('catalog/product')->load($pro->getId());?>
        <?php if ($i++%$_columnCount==0): ?>
            <?php endif ?>
            <li class="product-item item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?> quick<?php echo $_product->getId(); ?>">
                <div class=" productgrid" style="margin-bottom:15px;width:300px;height:300px;background: url('<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(370); ?>');background-repeat:no-repeat;background-size:cover;">
                    <a class="emptylink" href="<?php echo $_product->getProductUrl() ?>">
                        <?php if(in_array($_product->getSku(), $_gift_card_array ) === false): ?>
                        <div class="emptylinkdiv" style="position: relative">&nbsp;<div class="quickview hidden-phone" name="modal" onclick="jQuery('#simplemodal-container').show();  quickview(<?php echo $_product->getId() ?>, false); return false;"></div></div>
                        <?php endif; ?>
                    </a>
                </div>
                <div class="row-fluid listing-name-price">
                    <div class="lising_product_name"><a class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></div>
                    <span class="secret-sku hide"><?php echo $_product->getSku(); ?></span>
                    <div class="listing_product_price"><span class="product-price"><?php echo $this->getPriceHtml($_product, true) ?></span></div>
                </div>
            </li>
            <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        <?php endif ?>
        <?php endforeach ?>
            </ul>
    <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
    <div class="toolbar-bottom">
        <?php
        /* @var $toolbar Mage_Catalog_Block_Product_List_Toolbar */
        // get toolbars limits - overrides default pager limit
        $toolbar = Mage::getBlockSingleton('catalog/product_list_toolbar')->getAvailableLimit();
        /* @var $pager Mage_Page_Block_Html_Pager */
        $pager = $this->getLayout()->createBlock('page/html_pager', 'bootstrapped.standalone.pager');
        // set limit - uses category's instead of default pager's (10-20-50)
        $pager->setAvailableLimit($toolbar);
        // need to set collection
        $pager->setCollection($_productCollection);
        //set custom template
        $pager->setTemplate('catalog/product/list/pager.phtml');
        echo $pager->toHtml();
        ?>
    </div>
</div>
<?php endif; ?>
<script>
jQuery(document).ready(function() {
    var defaultoutheight = -1;
    jQuery(".listing-name-price").each(function(index) {
        if(jQuery(this).outerHeight() > defaultoutheight)   
        defaultoutheight = jQuery(this).outerHeight();  
    });
    jQuery(".listing-name-price").height(defaultoutheight);
});
</script>

我已将产品限制设置为20,并将第一页设为当前页面 但问题是我可以在第一页看到20个产品 这些相同的20个产品在下一页重复,依此类推.所以简而言之,我在所有页面中都有相同的20个产品

目前我的网站上有8000个产品,我在上面的文件(cms页面)中加载了所有这些产品。

请记住,我每页只需要20个产品。我已经对此cms页面进行了分页,但它无法正常工作

那么如何在所有页面中显示所有8000个产品(每页20个)?

最新回答
  • 2019-12-5
    1 #

    使用经典类别来显示您的要求.您可以在配置中设置页面大小,并且可以使用开箱即用的分页!

相关问题

  • magento2:如何使用REST API在Magento中添加产品?
  • magento 1.9:Chrome中的混合内容