Jump to content

Magento PHP HELP


mike305

Recommended Posts

I am looking for some help with a php problem. (I found this forum on google) and was hoping someone in here would be able to help me out.

 

I have a table here: Which list 1 row of 5 of the most recent products I have added to the Magento store.

 

My goal is to get 2 rows of 5 products - to show 10 products all together. It seems simple im sure. But I do not know PHP that well.

 

 

 

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>

 

<table id="new-products-list-table">

 

<tr>

   

<?php $i=0; foreach ($_products->getItems() as $_product): ?>

       

<?php if ($i>5): continue; endif; ?>

 

<td>

5 items here

</td>

 

<?php $i++; endforeach; ?>

   

<?php for($i;$i%5!=0;$i++): ?>

       

<td class="empty"> </td>

   

<?php endfor; ?>

   

 

</tr>

 

 

</table>

 

<?php endif; ?>

 

 

 

Above is just the summery of the code: I was trying to make it more readable on the eye.

 

Here is the full phtml code.

 

 

<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>

<table id="new-products-list-table">

    <tr>

    <?php $i=0; foreach ($_products->getItems() as $_product): ?>

        <?php if ($i>5): continue; endif; ?>

        <td>

            <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>

                <div class="compare"><a href="<?php echo $_compareUrl ?>"><?php echo $this->__('Compare Item') ?></a></div>

                <?php endif; ?>

            <a class="product-image" 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(150, 150) ?>" width="150" height="150" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>

            <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>)"><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>

            <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>

            <?php echo $this->getPriceHtml($_product, true, '-new') ?>

            <?php if($_product->isSaleable()): ?>

            <button class="button" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>

            <?php else: ?>

            <p class="availability"><span class="out-of-stock"><?php echo $this->__('Out of stock') ?></span></p>

            <?php endif; ?>

        </td>

    <?php $i++; endforeach; ?>

    <?php for($i;$i%5!=0;$i++): ?>

        <td class="empty"> </td>

    <?php endfor; ?>

    </tr>

</table>

<?php endif; ?>

 

 

 

Thank you for the help..

Link to comment
Share on other sites

Sorry your code is confusing to me, but just add another row using <tr> code in here </tr> and continue your $i or counting variable for another 5 products.

Hope that helps. Oh and in the future use the Code Brakets to highlight your code, makes it a hell of a lot easier to read then.

Link to comment
Share on other sites

  • 1 month later...
  • 3 years later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.