0

I have created one cms page and in this page I have added below code:

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

I have set product limit to 20 and set first page as a current page but the issue is that I can see 20 products in first page and these same 20 products are repeating in next page and so on. So in short I got same 20 products in all the pages

Currently I have 8000 products in my website and I loaded all these products in above file(cms page).

Keep in mind that I want only 20 products per page.I already have pagination this cms page but it is not working

So how can I display all 8000 products(20 per page) in all pages?

0

Use a classic category to display your requirements. You can set page size in configuration and the liste comes with pagination out of the box!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.