Magento PHP if语句“加载两个块”,否则只加载一个?

时间:2014-01-23 18:41:38

标签: php magento

也许它很简单,但我对php不太好 使用此代码,我可以加载Magento中类别顶部样式的静态块和顶部类别具有子项时底部的子类别 我想要做的是,当没有子类别时,它应该只加载块
否则因为造型会占据子猫所处的位置。 请查看我的代码,也许您了解:

<?php
    $_helper    = $this->helper('catalog/output');
    $_category  = $this->getCurrentCategory();
    $_imgHtml   = '';
    if ($_imgUrl = $_category->getImageUrl()) {
        $_imgHtml = '<div class="category-image"><img src="'.$_imgUrl.'" alt="'.$this->htmlEscape($_category->getName()).'" title="'.$this->htmlEscape($_category->getName()).'" /></div>';
        $_imgHtml = $_helper->categoryAttribute($_category, $_imgHtml, 'image');
    }
    $_catHtml = $this->getChildHtml('catalog.inline.subcat');
?>
<?php if (!Mage::registry('current_category')) return ?>
<?php $_categories = $this->getCurrentChildCategories() ?>
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?>
<?php if($_count): ?>

// load the blocks styled with ul and il backgrounds 

                <ul class="inline-categories"> 
                <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId(   $this->getCurrentCategory()->getLandingPage()    )->toHtml() ?> 
                <?php foreach ($_categories as $_category): ?>
                <li<?php if($_i == 1):?> class="first"<?php endif ?>><a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>>    
                <?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>)</li>
                <?php endforeach ?> 
                <?php endif; ?>     
                </ul>

                // here i need something like an "else" because the if($count) allready understand that this is not on count so should only load this that is without style //

               <?php echo $this->getLayout()->createBlock('cms/block')->setBlockId(   $this->getCurrentCategory()->getLandingPage()    )->toHtml() ?> 

                //end of this else thing, now should only load the cms/block alone without anything / end of page we are done...

1 个答案:

答案 0 :(得分:2)

您可以使用PHP的if / else语句,如下所示:

<?php if ($_count): ?>

    stuff if $_count is non-zero

<?php else: ?>

    other stuff if $_count is zero

<?php endif; ?>