修改主题支持两种菜单并存
在本站升级到Wordpress 3.0后,浏览了一下许久没有看过的themes目录,发现几个我喜欢的主题,经过一番试用,发现Mystique也就是您现在看到的主题最合我心意,后来才发现这也是digitalnature的作品,good job!
美中不足的是,Mystique配置界面中主菜单只能在无、链接、页面、分类目录和自定义菜单中做单选,我希望能把分类目录和自定义菜单并存,一起显示出来。可惜作者没有设计这样的功能。Hacking的真谛就是要自己动手,当然还有无私分享。下面我就贴出我的做法:
先来看看core.php中相关功能实现函数
View Code PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | // print the main navigation menu function mystique_navigation() { $navtype = get_mystique_option('navigation'); if($navtype): ?> <div class="shadow-left"> <div class="shadow-right clearfix"> <?php $nav_extra = apply_filters("mystique_navigation_extra", ''); // check for new icons and output if($nav_extra) echo '<p class="nav-extra">'.$nav_extra.'</p>'; ?> <ul id="navigation" class="clearfix"> <?php if((get_option('show_on_front')<>'page') && get_mystique_option('exclude_home')<>'1'): if(is_home() && !is_paged()): ?> <li class="active home"><a class="home active fadeThis" href="<?php echo get_settings('home'); ?>" title="<?php _e('You are Home','mystique'); ?>"><span class="title"><?php _e('Home','mystique'); ?></span><span class="pointer"></span></a></li> <?php else: ?> <li class="home"><a class="home fadeThis" href="<?php echo get_option('home'); ?>" title="<?php _e('Click for Home','mystique'); ?>"><span class="title"><?php _e('Home','mystique'); ?></span><span class="pointer"></span></a></li> <?php endif; endif; ?> <?php if($navtype=='categories'): mystique_list_categories(array('hide_empty' => false, 'exclude' => get_mystique_option('exclude_categories'))); elseif($navtype=='links'): $links = get_bookmarks(array( 'orderby' => 'name', 'order' => 'ASC', 'limit' => -1, 'category' => null, 'category_name' => get_mystique_option('navigation_links'), 'hide_invisible' => true, 'show_updated' => 0, 'include' => null, 'search' => '.')); foreach ($links as $link): if($link->link_target) $target = ' target="'.wp_specialchars($link->link_target).'"'; else $target = ''; if($link->link_rel) $rel = ' rel="'.wp_specialchars($link->link_rel).'"'; else $rel = ''; if($link->link_description) $title = ' title="'.wp_specialchars($link->link_description).'"'; else $title = ''; echo '<li><a class="fadeThis" href="'.$link->link_url.'"'.$target.$rel.$title.'><span class="title">'.$link->link_name.'</span><span class="pointer"></span></a><li>'; endforeach; else: mystique_list_pages(array('exclude' => get_mystique_option('exclude_pages'), 'sort_column' => 'menu_order')); endif; do_action('mystique_navigation'); ?> </ul> </div> </div> <?php endif; } |
可以看出,作者整体设计的时候,就没有想要让用户做复选,在条件判断中使用了连续的if … elseif… 实现。
我采用了一个偷懒的方法仅把
View Code PHP
1 | if($navtype=='categories'): |
注释掉,然后把接下来的
View Code PHP
1 | elseif($navtype=='links'): |
改成
View Code PHP
1 | if($navtype=='links'): |
就可以啦。
多谢了!我也在使用这个主题,导航栏可定制性有限,还得自己动手修改。