magento创建动态菜单 Create Dynamic CMS Navig

系统 1578 0

Introduction

As you know in Magento, catalog has dynamic menu but cms doesn’t in frontend.
If you are curios about how to create dynamic menu for CMS which can either be included in left or right sidebar for all CMS pages, then you are in right place.


Steps

1. Create navigation.phtml file
Create nagivation.phtml file in folder: app/design/frontend/[your-interface]/[your-theme]/template/cms/
and add the following code:

    <?php
$cmsPages = Mage::getModel('cms/page')->getCollection()
            ->addStoreFilter(Mage::app()->getStore()->getId())
            ->addFieldToFilter('is_active',1)
            ->addFieldToFilter('identifier', array(
                array(
                    'nin' => array(
                            'home',
                            'no-route',
                            'enable-cookies',
                            'empty'
                        )
                    )
                )
            );
?>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<style type="text/css">
    #cms-navigation a.active { color: red; }​
</style>
<script type="text/javascript">
jQuery.noConflict();
jQuery(document).ready(function() {
    var url = window.location.pathname,
    urlRegExp = new RegExp(url.replace(/\/$/,'') + "$");
    jQuery('#cms-navigation a').each(function(){
        if(urlRegExp.test(this.href.replace(/\/$/,''))){
            jQuery(this).addClass('active');
        }
    });
 });
</script>
<div class="block">
    <div class="block-title">
        <strong><span>CMS Navigation</span></strong>
    </div>
    <div class="block-content">
        <ul id="cms-navigation" style="padding: 10px;">
            <?php
            foreach($cmsPages as $_cms):
                $page = $_cms->getData();
                ?>
                <li><a href="<?php echo $this->getBaseUrl() . $page['identifier']; ?>"><?php echo $page['title']; ?></a></li>
                <?php
            endforeach;
            ?>
 
        </ul>
    </div>
</div>
  
 

OR
You can simply download the navigation.phtml file from [here]

 

2> Include CMS Navigation in Layout
Copy/paste the following XML code in your layout XML file (preferably in your theme’s local.xml file):

    <cms_page_view>
    <reference name="left"><!--or right-->
        <block type="core/template" name="cms-navigation" template="cms/navigation.phtml" before="-" />
    </reference>
</cms_page_view>
  
 

This will automatically include the CMS navigation in layout file.


Notes:
Make sure you select the proper Layout template from CMS form ( Design > Page Layout > Layout ).
For example, in order to include CMS navigation in left column you either have to use: Layout = 2 columns with left bar or 3columns .

 

3> That’s all.

If you visit the CMS pages in frontend you will see navigation with all the CMS pages dynamically included with current one being highlighted (see below snapshot).


This will of course make your CMS pages look more beautiful and user friendlier.

magento创建动态菜单 Create Dynamic CMS Navigation For Magento Frontend

CMS Navigation

 

Happy E-commerce!

 

来源: http://www.blog.magepsycho.com/create-dynamic-cms-navigation-for-magento-frontend/

 

 

magento创建动态菜单 Create Dynamic CMS Navigation For Magento Frontend


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论