2014-01-23 27 views
0

也許是簡單的東西,但是當頂部類別有孩子
我不是用PHP
有了這個代碼,我能夠加載在Magento類的頂部風格的靜態塊和底部子類別真的好什麼我試圖做的是,當沒有子類別時,它應該只加載塊
,否則由於樣式它將保持子卡位置的位置。 請對我的代碼來看看,也許你明白:
Magento PHP if語句「加載兩個塊」,否則只加載一個?

<?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... 

回答

2

您可以使用PHP的if/else語句是這樣的:

<?php if ($_count): ?> 

    stuff if $_count is non-zero 

<?php else: ?> 

    other stuff if $_count is zero 

<?php endif; ?> 
+1

感謝這麼多,我整理了這一點完全相同的方式只是5'後,我張貼在這裏!!猜我越來越好:) – spanakorizo