2013-04-12 45 views
0

任何人都可以幫助我?Magento以某種方式獲取分類名稱

我有一個顯示自定義標題圖像的產品模板。它的工作原理如下: 當我添加一個帶有pagename的靜態塊,然後在它後面添加-header,然後在頁面上顯示該靜態塊(標識符)。該塊不存在,則顯示默認頭靜態塊。

需要做的是抓住主要類別名稱(-header)並將其放置在自定義的1column-product.phtml模板中,我在其中加載了默認標題(標識符)。

線77:

// GET DEFAULT HEADER 
echo Mage::getModel(‘cms/block’)-> load(‘default-header’)-> getContent(); 

「默認頭」必須「類別名頭」

我不認爲這是很難做到的,但我不是一個編碼器:(

總代碼:

<header>  
<?php echo $this->getChildHtml('header') ?> 
<section id="subtop" class="clearfix"> 
<div class="slideContainer clearfix"> 

<?php 
if ($this->getUrl('') == $this->getUrl('*/*/*', array('_current'=>true, '_use_rewrite'=>true))) { 
// HOMEPAGE IS TRUE 
$cmsBlock = Mage::getModel('cms/block')->load('flexslider')->getContent(); 
if($cmsBlock) { 
echo $cmsBlock; 
} 
}else{ 


echo '<div class="pghead clearfix ABC">';   
if(Mage::getModel('cms/block')->load('default-header')->getContent()){ 
// GET DEFAULT HEADER 
echo Mage::getModel('cms/block')->load('default-header')->getContent(); 
} 
// promotion banner 
echo '</div>'; 
if(Mage::getModel('cms/block')->load('promotion')->getContent()){ ?> 
<div class="promotion"> 
<div class="container"> 
    <?=Mage::getModel('cms/block')->load('promotion')->getContent(); ?> 
</div> 
</div> 
<? } // promotion banner 

} //Flexslider ?> 
</div><!-- slidecontainer --> 
+0

有沒有人知道如何做到這一點? – user123

+0

任何人都可以把我推向正確的方向? – user123

回答

0
//if you are in category or product page 
    $currentCategory = Mage::registry('current_category'); 
//or load category if you are in pages other than product or category page 
// $currentCategory = Mage::getModel('catalog/category')->load(12); 
    $blockName = $currentCategory->getName().'-header'; 
    echo Mage::getModel(‘cms/block’)-> load($blockName)-> getContent(); 

如果您在產品或類別頁面中,則可以使用Magento註冊表加載當前類別。如果它在其他頁面中,則需要通過其他方式加載類別。

相關問題