tags:

views:

52

answers:

1

I have the below code in a page.

<?php if($this->getMode()!='grid'): ?>
<?php $_iterator = 0; ?>
<div class="listing-type-list catalog-listing top10full" onclick='window.open("http://google.com")'&gt;

<?php 
$i = 0;
foreach ($_productCollection as $_product): 
$i++;
?>

    <div class="listing-number"><p class="listing-position"><?php echo $i ?></p></div>
    <div class="listing-item<?php if( ++$_iterator == sizeof($_productCollection) ): ?> last<?php endif; ?>">
        <?php // Product Image ?>
        <div class="product-image">
            <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getSmallImageLabel()) ?>">
                <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(135, 135); ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>" />
            </a>
        </div>

I would like to replace http://google.com with the product url:

<?php echo $_product->getProductUrl() ?>

However the above way of getting the product url only works when inside the foreach loop.

How can I get this to work?

+1  A: 

Which product do you want to use to replace http://google.com? There is one link and many products.

You can try to use first one <?php $pr = $_productCollection[0]; echo $pr->getProductUrl() ?>

Sam Dark
that div gets repeated for each product so I would like the link to be for the current product.
a1anm
If the div gets repeated for each product, why don't you put it into the loop?
Matěj Grabovský