销售产品不显示标题,如果没有产品返回


Sale products not to display title if no products are returned.

我有这段代码,其中显示了4种正在销售的产品,但是我想把它包装在IF语句中,基本上说如果没有产品,那么不显示任何东西。例如,如果没有产品,它仍然显示标题"这些伟大的产品正在出售"。我知道这似乎是一个简单的任务,但当你没有真正使用过PHP,那么它是非常有压力的。

<?php
Mage::getSingleton('core/session', array('name' => 'frontend'));
$_category = Mage::registry('current_category');
            $currentCategoryId= $_category->getId();
$_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
            ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
            ->addMinimalPrice()
            ->addCategoryFilter($_category)
            ->addStoreFilter();
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($_productCollection);

$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);
$_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
    ->addAttributeToFilter('special_to_date', array('or'=> array(
    0 => array('date' => true, 'from' => $tomorrowDate),
    1 => array('is' => new Zend_Db_Expr('null')))
    ), 'left');
?>
<div class="for_sale_div">
<!--heading for sale products-->
<h1 class="sale_title"> These Great Products Are On Sale</h1>
<!-- set it into a grid format -->
<div class="products-grid two_columns_5">
<?php $_collectionSize = $_productCollection->count() ?>
<?php $i=0; foreach($_productCollection as $_product):?>
<?php if($i++%3==0): ?>
<ol class="grid">
 <?php endif; ?>
<li class="item">

<p class="product-image">
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($this->getImageLabel($_product, 'small_image')) ?>">
                        <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>
                </p>
                <h5><a href="<?php echo $_product->getProductUrl() ?>" 
                title="<?php echo $this->htmlEscape($_product->getName()) ?>">
                <?php echo $this->htmlEscape($_product->getName()) ?></a></h5>
                <?php if($_product->getRatingSummary()): ?>
                <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
                <?php endif; ?>
                <?php echo $this->getPriceHtml($_product, true) ?>
                 </li>
        <?php if($i%3==0 || $i==$_collectionSize): ?>
        </ol>
        <?php endif; ?>
    <!-- Set the product count to 4-->
    <?php if($this->getIsHomepage() && $i==4) break; ?>
 <?php endforeach ?>
 </div>
 </div>

如果你能帮忙,谢谢你。

如果您不想显示标题,如果没有从集合返回的产品,那么您可以这样做

<?php if($_productCollection->count() > 0):?>
<h1 class="sale_title"> These Great Products Are On Sale</h1>
<?php endif;?>

您可以在此IF条件下包装任何您想要的<div>