Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento PHP if语句;“加载两个块”,否则只加载一个?_Php_Magento - Fatal编程技术网

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

Magento PHP if语句;“加载两个块”,否则只加载一个?,php,magento,Php,Magento,也许这很简单,但我对php不是很在行 有了这段代码,我可以加载Magento中类别顶部样式的静态块,以及顶部类别有子类别时底部的子类别 我想做的是,当没有子类别时,它应该只加载块 否则,由于样式设置的原因,它将保留子类别的位置。 请看一下我的代码,也许你能理解: <?php $_helper = $this->helper('catalog/output'); $_category = $this->getCurrentCategory(); $

也许这很简单,但我对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...

您可以像这样使用PHP的if/else语句:

<?php if ($_count): ?>

    stuff if $_count is non-zero

<?php else: ?>

    other stuff if $_count is zero

<?php endif; ?>

如果$\u计数为非零,则填充
如果$\u计数为零,则为其他内容

非常感谢,我在这里发帖5分钟后就以同样的方式整理了这篇文章!!我想我正在好转:)