代码之家  ›  专栏  ›  技术社区  ›  a1anm

PHP产品Url

  •  0
  • a1anm  · 技术社区  · 16 年前

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

    http://google.com 使用产品url:

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

    然而,上述获取产品url的方法仅在foreach循环内有效。

    我怎样才能让它工作?

    1 回复  |  直到 16 年前
        1
  •  1
  •   Sam Dark    16 年前

    您想用哪种产品来替换 http://google.com ? 有一个环节,有很多产品。

    你可以试着用第一个 <?php $pr = $_productCollection[0]; echo $pr->getProductUrl() ?>

    推荐文章