2012-04-03 37 views
1

我已經創建了一個左側邊欄導航模板,可以通過兩種類別(動態)和CMS頁面手動添加(請參見下面的代碼)和I已經設法獲得活動狀態,但我最好是動態地拉動頁面,然後添加活動狀態。有任何想法嗎?提前致謝。動態檢索CMS頁面並基於Magento中的當前頁面標識符添加活動狀態

<?php $_menu = $this->renderCategoriesMenuHtml(0,'level-top') ?> 
<?php if($_menu): ?> 
<?php 
$current_page = ''; 
/* 
* Check to see if its a CMS page 
* if it is then get the page identifier 
*/ 
if(Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms'): 
    $current_page = Mage::getSingleton('cms/page')->getIdentifier(); 
endif 
?> 
<nav class="nav-container"> 
<ul id="nav"> 
    <?php echo $_menu; ?> 
    <li <?php if ($current_page == 'home') { echo 'class="active"'; } else { echo 'class="home"'; } ?>><a href="<?php echo $this->getUrl('home')?>"><span><?php echo $this->__('Home') ?></span></a></li> 
    <li <?php if ($current_page == 'about') { echo 'class="active"'; } else { echo 'class="about"'; } ?>><a href="<?php echo $this->getUrl('about')?>"><span><?php echo $this->__('About') ?></span></a></li> 
    <li <?php if ($current_page == 'faqs') { echo 'class="active"'; } else { echo 'class="faqs"'; } ?>><a href="<?php echo $this->getUrl('faqs')?>"><span><?php echo $this->__('FAQS') ?></span></a></li> 
    <li <?php if ($current_page == 'contacts') { echo 'class="active"'; } else { echo 'class="contacts"'; } ?>><a href="<?php echo $this->getUrl('contacts')?>"><span><?php echo $this->__('Contact Us') ?></span></a></li> 
    <li <?php if ($current_page == 'artworks') { echo 'class="active"'; } else { echo 'class="artworks"'; } ?>><a href="<?php echo $this->getUrl('artworks')?>"><span><?php echo $this->__('Artworks') ?></span></a></li> 
    <li <?php if ($current_page == 'how-it-works') { echo 'class="active"'; } else { echo 'class="how-it-works"'; } ?>><a href="<?php echo $this->getUrl('how-it-works')?>"><span><?php echo $this->__('How it Works') ?></span></a></li> 
</ul> 
</nav> 
<?php endif ?> 

回答

0

羅伯特·肯特an example of dynamically building Magento CMS page lists通過遍歷CMS頁面收集和排除無效,系統頁面(沒有餅乾,沒有路由等)的作品。

要處理的活動狀態簡單地比較$current_page反對$page['identifier']價值foreach循環中:

foreach ($_menu_cms as $cmspage) { 
    $page = $cmspage->getData(); 
    if (! in_array($page['identifier'], array('no-route', 'enable-cookies'))) { 
    $class = ($page['identifier'] == $current_page ? 'active' : ''); 
    printf('<li><a href="%s" title="%s" class="%s">%s</a></li>', 
     $this->getUrl($page['identifier'], $this->htmlEscape($page['title']), $class, $page['title'] 
    ); 
    } 
} 
相關問題