Magento Forum

Page 1 of 2
How do I change # items/row in new.phtml? 
 
mrgad
Member
 
Total Posts:  60
Joined:  2008-08-29
 

From elsewhere on this forum, I learned it is very easy to edit list.phtml to change the # of items that display per row on catalog pages.

I am featuring NEW products on my homepage, and calling new.phtml to do so.

I’ve tried to match the settings in list.phtml as a model to change the # of items in a row before the row automatically breaks, but without success.  I’m ALMOST there, but not quite.

Can someone please help?  This should be an easy one.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rudack
Jr. Member
 
Total Posts:  10
Joined:  2008-07-09
 

I am also having the same problem.

I want to display 5 rows with 8 items per row.  How can this be accomplished?  Surely someone out there knows?  Anyone’s help will be greatly appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
true82
Jr. Member
 
Total Posts:  10
Joined:  2008-11-05
 

I am in a similar boat here..... Looking to do 2 rows of 5 each.... Where are you magento gurus! save us!! smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

You guys are asking different questions.
@mrgad:  You don’t say what’s wrong, so I’m guessing that you got your answer by now.

@rudack and @true82:  You’re going to have to change the code that loads the list of new products to display.  The template has a default of 5 built into the loop, but the code in app/code/core/Mage/Catalog/Block/Product/New.php also has a default of 5 built in. There is, however, a function already coded called setProductCount, so you can figure out where/if it’s already being called and change the number. Otherwise, you’ll only ever retrieve 5 products to display for that block.

 
Magento Community Magento Community
Magento Community
Magento Community
 
rudack
Jr. Member
 
Total Posts:  10
Joined:  2008-07-09
 
joyously - 13 November 2008 05:20 PM

You guys are asking different questions.
@mrgad:  You don’t say what’s wrong, so I’m guessing that you got your answer by now.

@rudack and @true82:  You’re going to have to change the code that loads the list of new products to display.  The template has a default of 5 built into the loop, but the code in app/code/core/Mage/Catalog/Block/Product/New.php also has a default of 5 built in. There is, however, a function already coded called setProductCount, so you can figure out where/if it’s already being called and change the number. Otherwise, you’ll only ever retrieve 5 products to display for that block.

Joyously, thanks for the reply.  I am able to edit and add the product count.  The problem is if I set the limit to higher than 8 all of the New Products are on the same line and basically break the look of the site.  My site is using a modified version of the modern theme.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Leo27
Sr. Member
 
Total Posts:  127
Joined:  2008-10-08
 

Same problem here!

No matter what I do, no matter what I change, products are always displayed it the same and only row!

Did anybody already solved this?

Help would be apreciated,

best regards
L. Nunes

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

Looks pretty simple to me. In template/catalog/product/new.phtml you’ll see that the list is output with a table. There is only one row tag (<tr>) and a cell for each product (<td>) which means they will just keep going across.
So just change it to make more rows or don’t use a table. You can use an unordered list and style it to float left and they will automatically fill the space provided. If you change the tags, be sure to find it in the style sheet to make sure they didn’t code the tags in there. The 1.1.6 release made a change to Product Grid view. It used to be a table and they changed it to an ordered list. The display of it was funky because they didn’t catch all the changes needed in the style sheet. You can use that one (the grid part of template/catalog/product/list.phtml) as an example for how to do this one.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Leo27
Sr. Member
 
Total Posts:  127
Joined:  2008-10-08
 

Thanks for the reply joyously!

well, it looks hard to me, I’m really a newbie lol…

Can you tell me how can I change it to make more rows?

I’ve also tried removing the table, but it now displays only one product per row , how can I adjust it? css?

Thanks,

Best regards
L. Nunes

 
Magento Community Magento Community
Magento Community
Magento Community
 
Leo27
Sr. Member
 
Total Posts:  127
Joined:  2008-10-08
 

humm, well removing the table and adding a float: left, I make it work, but only in firefox..
In I.E. it’s still in the same line!
So I really need to make this other way, using more rows, more 2…

I was studying the list.phtml , and what seems to make the rows change is <?php if($i++%3==0): ?> , when 3 products have been reached ($_collectionSize) will make it change row…

But how can I implement this in my new.phtml?

Best regards
L. Nunes

 
Magento Community Magento Community
Magento Community
Magento Community
 
rudack
Jr. Member
 
Total Posts:  10
Joined:  2008-07-09
 

Many thanks.  This code actually gave me 5 rows of 5 and it worked perfectly.  Thanks for the push in the right direction Jously.

I hope this helps others.

?>
<?php 
if (($_products $this->getProductCollection()) && $_products->getSize()): ?>
<div class="box recently">
<
table cellspacing="0" class="recently-list" id="recently-compared-list-table">
<
tr>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
    <?php 
if ($i++%5==0): ?>
    
<tr>
    
<?php endif ?>
        
<td>
        <
div>
            <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <
img class="product-image" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(80, 77) ?>" width="80" height="77" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
            </
a>
        </
div>
            <
p><class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
            
<?php echo $this->getReviewsSummaryHtml($_product'short'?>
            <?php 
echo $this->getPriceHtml($_product?>
            <?php 
if($_product->isSaleable()): ?>
            
<button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart'?></span></button>
            
<?php else: ?>
            
<div class="out-of-stock"><?php echo $this->__('Out of stock'?></div>
            
<?php endif; ?>
            
<div class="clear"></div>
            <
class="add-to">
                
<?php if ($this->helper('wishlist')->isAllow()) : ?>
                
<a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist'?></a>
                
<?php endif; ?>
                <?php 
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?><br/>
                <
a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare'?></a>
                
<?php endif; ?>
            
</p>
        </
td>
<?php $i++; endforeach; ?>
<?php 
for($i;$i%5!=0;$i++): ?>
        
<td>&nbsp;</td>
    
<?php endfor ?>
    
</tr>
</
table></div>
<?php endif; ?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
Zerosports
Jr. Member
 
Total Posts:  11
Joined:  2008-12-02
 

I tried the above code for 1.8 . it only shows 5 colums, and 1 row .

 
Magento Community Magento Community
Magento Community
Magento Community
 
Costa
Member
 
Avatar
Total Posts:  56
Joined:  2007-11-21
Shenzhen China
 
joyously - 13 November 2008 05:20 PM

You guys are asking different questions.
@mrgad:  You don’t say what’s wrong, so I’m guessing that you got your answer by now.

@rudack and @true82:  You’re going to have to change the code that loads the list of new products to display.  The template has a default of 5 built into the loop, but the code in app/code/core/Mage/Catalog/Block/Product/New.php also has a default of 5 built in. There is, however, a function already coded called setProductCount, so you can figure out where/if it’s already being called and change the number. Otherwise, you’ll only ever retrieve 5 products to display for that block.

Hey Joy,

Thanks for your great advise. Can you please tell where exactly to i set setProductCount without altering the app/code/core/Mage/Catalog/Block/Product/New.php ? Can it be done from within new.phtml template file?

Really appreciate your help
Costa

 
Magento Community Magento Community
Magento Community
Magento Community
 
Costa
Member
 
Avatar
Total Posts:  56
Joined:  2007-11-21
Shenzhen China
 

Someone must have an answer please?  rasberry

 
Magento Community Magento Community
Magento Community
Magento Community
 
DCAlmeida
Sr. Member
 
Avatar
Total Posts:  164
Joined:  2008-12-28
PRT
 

I have a problem! Even if I change the number of new.phml or New.php, in my frontpage only appear one row!! If I change to some number above 5, all the site brokes, the div expands to out of limits.

Any solution to this?

 
Magento Community Magento Community
Magento Community
Magento Community
 
rickygri
Jr. Member
 
Total Posts:  22
Joined:  2009-01-17
 

I went to: app/code/core/Mage/Catalog/Block/Product/New.php and changed:

const DEFAULT_PRODUCTS_COUNT 5;

to:

const DEFAULT_PRODUCTS_COUNT 10;

and updated parameters in the new.phtml file to 10:

<?php if (($_products $this->getProductCollection()) && $_products->getSize()): ?>
<div class="blockinfobox">
<
div class="box recently">
<
table cellspacing="0" class="recently-list" id="recently-compared-list-table">
<
tr>
<?php $i=0; foreach ($_products->getItems() as $_product): ?>
    <?php 
if ($i++&#x10;==0): ?>
    
<tr>
    
<?php endif ?>
        
<td>
        <
div>
            <
a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <
img class="product-image" src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(80, 77) ?>" width="80" height="77" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
            </
a>
        </
div>
            <
p><class="product-name" href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></p>
            
<?php echo $this->getReviewsSummaryHtml($_product'short'?>
            <?php 
echo $this->getPriceHtml($_product?>
            <?php 
if($_product->isSaleable()): ?>
            
<button class="form-button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart'?></span></button>
            
<?php else: ?>
            
<div class="out-of-stock"><?php echo $this->__('Out of stock'?></div>
            
<?php endif; ?>
            
<div class="clear"></div>
            <
class="add-to">
                
<?php if ($this->helper('wishlist')->isAllow()) : ?>
                
<a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-cart"><?php echo $this->__('Add to Wishlist'?></a>
                
<?php endif; ?>
                <?php 
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?><br/>
                <
a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Add to Compare'?></a>
                
<?php endif; ?>
            
</p>
        </
td>
<?php $i++; endforeach; ?>
<?php 
for($i;$i&#x10;!=0;$i++): ?>
        
<td>&nbsp;</td>
    
<?php endfor ?>
    
</tr>
</
table>
</
div>
</
div>
<?php endif; ?>

Then added a div in boxes.css:

.blockinfobox { height:440pxwidth:690pxmargin-top:16pxborder:1px solid #5c7989; padding-left:50px; padding-top:10px; float:left; display:inline; }

The new.phtml file is now contained in a div which floats left, and the new.php and new.phtml files are both set to limits of 10. This seemed to allow for 10 new products, which automatically fill the div to 2 rows of 5. The css is just a border to show where its being contained. Also, this div will fit in the main column of the ‘2 column-left layout’, but will not display correctly in a 3 column, just change the div width/height to fit your template.

Hope this helps someone!

 
Magento Community Magento Community
Magento Community
Magento Community
 
matte
Member
 
Total Posts:  54
Joined:  2008-12-04
Buonacompra
 

Rickygri....  surprised  surprised  surprised  surprised

Thanks!!!

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2