jcadima
5/15/2015 - 1:57 PM

Show Static Blocks Based on Category ID

Show Static Blocks Based on Category ID

<?php
// This will show individual banners for the selected category ID
// /app/design/frontend/mthoro/default/template/catalog/cateogry/view.phtml

    <div class="col-lg-3 category-nav"> <?php echo $this->getLayout()
            ->createBlock("mthoro/mainmenu_menu")
            ->setTemplate("magenthemes/mainmenu/categories.phtml")
            ->toHtml();?>
    </div>
    
    <div class="col-lg-9">
    <?php $category = Mage::getModel('catalog/layer')->getCurrentCategory();?>
    <?php // echo "<h1>Current Category ID: {$category->getId()}</h1>" ; ?>
    	<?php if  ( $category->getId() == 5): ?>
		<?php	echo $this->getLayout()->createBlock('cms/block')->setBlockId('luggage-banner')->toHtml();  ?>

    	<?php elseif  ( $category->getId() == 4): ?>
		<?php	echo $this->getLayout()->createBlock('cms/block')->setBlockId('brands-banner')->toHtml();  ?>
		
    	<?php elseif  ( $category->getId() == 12): ?>
		<?php	echo $this->getLayout()->createBlock('cms/block')->setBlockId('bags-banner')->toHtml();  ?>
		
    	<?php elseif  ( $category->getId() == 6): ?>
		<?php	echo $this->getLayout()->createBlock('cms/block')->setBlockId('backpack-banner')->toHtml();  ?>		

    	<?php elseif  ( $category->getId() == 7): ?>
		<?php	echo $this->getLayout()->createBlock('cms/block')->setBlockId('duffels-banner')->toHtml();  ?>

						
		<?php else: ?>
 <!-- default Content -->
<?php endif; ?>
    </div>