Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7047381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:45:52+00:00 2026-05-28T02:45:52+00:00

The question is pretty simple, the code below shows the items in one category.

  • 0

The question is pretty simple, the code below shows the items in one category. Those categories have 4 products.
However my plan is to put in those categories 20 products, and make the following code to choose randomly 4 products of those categories.

I suppose the only line I need to change is this:

$_productCollection=$this->getLoadedProductCollection();



<?php
/**
 * Product list template
 *
 * @see Mage_Catalog_Block_Product_List
 */
?>
<?php
$_productCollection=$this->getLoadedProductCollection();
$_helper = $this->helper('catalog/output');
?>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">

    <?php // List mode ?>

    <?php $_iterator = 0; ?>

    <script type="text/javascript">decorateList('products-list', 'none-recursive')</script>



    <?php // Grid Mode ?>

    <?php $_collectionSize = $_productCollection->count() ?>
    <?php $_columnCount = $this->getColumnCount(); $_columnCount=4; ?>
    <?php $i=0; foreach ($_productCollection as $_product): ?>
        <?php if ($i++%$_columnCount==0): ?>
        <ul class="products-grid">
        <?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"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(170); ?>" width="170" height="170" alt="<?php echo $this->stripTags($this->getImageLabel($_product, 'small_image'), null, true) ?>" /></a>
                 <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; ?>

                <div class="actions">
                    <div style="clear:both;"></div>
                    <div>
                        <?php $Deal = $_product->getResource()->getAttribute('deal')->getFrontend()->getValue($_product);?>
                                <?php $onSale = $_product->getResource()->getAttribute('on_sale')->getFrontend()->getValue($_product);?>
                                <?php $hotItem = $_product->getResource()->getAttribute('hot_item')->getFrontend()->getValue($_product);?>
                                <?php $freeShip = $_product->getResource()->getAttribute('free_shipping')->getFrontend()->getValue($_product);?>
                                <?php if($Deal == 'Yes'){ ?>
                                    <img width="91px" height="21px" alt="Deal" title="Deal" src="<?php echo $this->getSkinUrl('images/icon-deal.gif') ?>" oncontextmenu="return false" >
                                <?php } ?>
                                <?php if($onSale == 'Yes'){ ?>
                                    <img width="91px" height="21px" alt="On Sale" title="On Sale" src="<?php echo $this->getSkinUrl('images/icon-sale.gif') ?>" oncontextmenu="return false" >
                                <?php } ?>
                                <?php if($hotItem == 'Yes'){ ?>
                                    <img width="91px" height="21px" alt="Hot Item" title="Hot Item" src="<?php echo $this->getSkinUrl('images/icon-hot.gif') ?>" oncontextmenu="return false" >
                                <?php } ?>
                                <?php if($freeShip == 'Yes'){ ?>
                                    <img alt="Free Shipping" width="91px" height="21px" title="Free Shipping" src="<?php echo $this->getSkinUrl('images/icon-freeship.gif') ?>" oncontextmenu="return false" >
                                <?php }?>
                    </div>
                </div>
                <?php echo $this->getPriceHtml($_product, true) ?>



                <div class="actions">
                    <?php if($_product->isSaleable()): ?>
                        <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" 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; ?>
                    <?php /*?><ul class="add-to-links">
                        <?php if ($this->helper('wishlist')->isAllow()) : ?>
                            <li><a href="<?php echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
                        <?php endif; ?>
                        <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
                            <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
                        <?php endif; ?>
                    </ul><?php */?>
                </div>


            </li>
        <?php if ($i%$_columnCount==0 || $i==$_collectionSize): ?>
        </ul>
        <?php endif ?>
        <?php endforeach ?>
        <script type="text/javascript">decorateGeneric($$('ul.products-grid'), ['odd','even','first','last'])</script>    


</div>
<?php endif; ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T02:45:53+00:00Added an answer on May 28, 2026 at 2:45 am

    Try this:

    <?php
    
    // $_productCollection = $this->getLoadedProductCollection();
     $_helper = $this->helper('catalog/output');
     $_category = Mage::getModel('catalog/category')->load($this->getCategoryId());
     $_productCollection = Mage::getResourceModel('reports/product_collection')
                           ->addAttributeToSelect('*')
                           ->addCategoryFilter($_category)
                           ->setVisibility(array(2,3,4));
     $_productCollection->getSelect()->order(new Zend_Db_Expr('RAND()'));                  
     $_productCollection->setPage(1, 4);
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my question is a pretty simple one, however I simply cannot see where i
My question is pretty simple: If you have two web-application components: Server-side (secret-capable) code
Pretty simple question: When i have a persistable object, it usually has a property
Pretty simple question. I have a few ASP RequiredFieldValdators checking some text boxes. Out
I have a pretty simple question which perhaps someone familiar with Server/Client design &
i have pretty simple simple question (i hope so). How do i change the
Hopefully this is a pretty simple question! I've got the code working in jQuery
I have a pretty simple question, but for some reason I am drawing a
My question is pretty simple: Q: Do get and set functions have an increased
I have a pretty simple question: how can I terminate a running script in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.