Displaying 3 items instead of 4

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Displaying 3 items instead of 4

Post by Danielc1234 »

Hi all. Since I am not a php guy at all, I was hoping someone could point this out for me.
I am trying to display 4 items across instead of 3. I'm not sure which line of code does this. I want to hard wire in 4 items across if possible and maybe clean up some of the unnecessary code that is in here. I got this from a program we have that will display in a grid or list mode. I only want it to display in a grid mode. So if there is a way to take out the list mode parts that would be great too.

Thanks in advance - Daniel
:crazy:

Code: Select all

 
<?php $_productCollection=$this->getLoadedProductCollection() ?>
 
<?php if(!$_productCollection->count()): ?>
 
<?php else: ?> 
 
<?php // List mode ?>
<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
 
<?php else: ?>
 
<?php // Grid Mode ?>
<div class="listing-type-grid-homepage  catalog-listing-homepage"> <!-- the class name will change to .listing-type-cell if viewing in list mode -->
<?php $_collectionSize = $_productCollection->count() ?>
    <table cellspacing="0" class="homepage-product-grid" id="product-list-table">
    <?php $i=0; foreach ($_productCollection as $_product): ?>
    <?php if ($i++%3==0): ?>
    <tr>
    <?php endif ?>
        <td>
            <p class="product-image">
                <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                   <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(160, 160); ?>" width="160" height="160" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" />
 
                </a>
            </p>
            <h2><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><?php echo $this->htmlEscape($_product->getName()) ?></a></h2>
            <?php echo $this->getPriceHtml($_product, true) ?>
            <?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: ?>
            <?php endif; ?>
            <div class="clear"></div>
        </td>
    <?php if ($i%3==0 && $i!=$_collectionSize): ?>
    </tr>
    <?php endif ?>
    <?php endforeach ?>
    <?php for($i;$i%3!=0;$i++): ?>
          <td class="empty-product">&nbsp;</td>
    <?php endfor ?>
    <?php if ($i%3==0): ?>
    </tr>
    <?php endif ?>
    </table>
    <script type="text/javascript">decorateTable('product-list-table')</script>
</div>
<?php endif; ?>
<?php endif; ?>
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Displaying 3 items instead of 4

Post by onion2k »

Did you try changing anything? That should always be your first port of call - read the code and change things to see what happens. So long as you have a backup nothing can go wrong.
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Re: Displaying 3 items instead of 4

Post by Danielc1234 »

I have a backup and have made some small changes, but since I do not know php that well, I am not having much luck.
There was two display features grid and list. Which I only want to use grid and to hard wire to display 4 items accross instead of 3, but dont know which code does that.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Displaying 3 items instead of 4

Post by califdon »

nothing can go wrong.
...can go wrong ... can go wrong ... can go wrong ... :P

Seriously, let's try to help this guy, at least with setting the number of columns. Do you see the lines that read:

Code: Select all

    <?php if ($i%3==0 && $i!=$_collectionSize): ?>
    ...
    <?php for($i;$i%3!=0;$i++): ?>
    ...
    <?php if ($i%3==0): ?>
Try changing those 3s to 4s.

To eliminate the list view, I'd have to spend more time looking at your code, but if it's not causing you a problem, you could just leave it alone. Might be less problem than if you try to modify it and get it wrong.
Danielc1234
Forum Newbie
Posts: 18
Joined: Tue Jul 29, 2008 11:55 am

Re: Displaying 3 items instead of 4

Post by Danielc1234 »

Yes! That worked....thanks a lot!
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: Displaying 3 items instead of 4

Post by onion2k »

Do you understand why it worked?
Post Reply