clare485
11/20/2013 - 1:19 PM

Magento example of how to limit number of products loaded in list This is better: http://stackoverflow.com/questions/16482486/how-to-displa

Magento example of how to limit number of products loaded in list

This is better: http://stackoverflow.com/questions/16482486/how-to-display-only-3-related-product-on-product-view-page-magento

 <?php $i = 0; ?>
    <?php foreach($this->getItems() as $_item): ?>
        <?php if($i++ == 3) break; ?>


<?php
/**
 * Magento responsive theme
 *
 * @category    design
 * @package     mirror
 * @copyright   Copyright (c) 2012 Magenthon (http://magenthon.com)
 * @license     http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 * @author      Vedran Subotic <vedran@magenthon.com>
 */
?>
<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>



<?php
    $_productCollection=$this->getLoadedProductCollection();
    $_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<div class="alert fade in">
  <a class="close" data-dismiss="alert">×</a>
  <?php echo $this->__('There are no products matching the selection.') ?>
</div>
<?php else: ?>
<div class="row">
<div class="category-products block block-featured pagination-centered span12">
    <div class="block-title">
        
        
        <h2>Bespoke mirrors</h2>      
         <p class="f-right testimonials-link"><a href="<?php echo $this->getUrl('testimonials')?>"><?php echo $this->__('To help you buy with confidence view our testimonials page') ?></a></p>
        
        </div>
    <?php // echo $this->getToolbarHtml() ?>
    <?php // List mode ?>
   
    <?php $_iterator = 0; ?>
    
    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>

    <div class="block-content" >

    <?php // Grid Mode ?>

    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = 20; ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if($i>20){
            break;
        } ?>
        
        <?php if ($i++%$_columnCount==0): ?>
            <ul id="carousel-just-in" class="products-grid unstyled">
            <?php endif ?>
            <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
    
                 
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" class="product-image thumbnail"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(225); ?>" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
                
                <div class="caption">
                    <h2 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>"><?php echo $_helper->productAttribute($_product, $_product->getName(), 'name') ?></a></h2>
                    <?php if($_product->getRatingSummary()): ?>
                    <?php // echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                    <?php endif; ?>
                    <?php echo $this->getPriceHtml($_product, true) ?>
                    <?php /* if($_product->isSaleable()): ?>
                        <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="btn btn-danger btn-mini" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
                    <?php else: ?>
                        <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
                    <?php endif;  ?>
                    <p class="add-to-links unstyled">
                        <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                        <a href="<?php echo $_compareUrl ?>" class="link-compare label label-info pull-right"><?php echo $this->__('Add to Compare') ?></a>
                        <?php endif; ?>
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist label label-info"><?php echo $this->__('Add to Wishlist') ?></a>
                        <?php endif; */ ?>

                    </p>
                </div>
                
            </li>
            <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
            </ul>
        <?php endif ?>
        <?php endforeach ?>
        <a class="prev" id="prev" href="#"><span>prev</span></a>
        <a class="next" id="next" href="#"><span>next</span></a>
    <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>
 

    </div><!--end-span-11-->
    <div class="clearfix"></div>
</div>
</div><!--end row-->



<?php endif; ?>