如果你在使用江阴印刷网风格,而且升级到了WordPress3.0,那么你可以看看主题在3.0下首页的分类名不显示的解决办法,而这篇是使主题支持自定义菜单并支持二级分类。
编辑functions.php文件,在 include (TEMPLATEPATH . ‘/settings.php’); 下添加
1 2 3 4 5 6 7 8 9 | register_nav_menus( array( 'primary' => __( 'Primary Navigation', 'cnt1' ), ) ); function cnt1_page_menu_args( $args ) { $args['show_home'] = true; return $args; } add_filter( 'wp_page_menu_args', 'cnt1_page_menu_args' ); |
编辑header.php文件,查找下例代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | <ul class="menu"> <li<?php if ( is_home()) { ?> class="current-cat"<?php } ?>><a href="<?php echo get_option('home'); ?>/"><?php _e('Home', 'ctn1'); ?></a></li> <?php wp_list_categories('title_li=&depth=1&orderby=id'); ?> <li class="feedrss"><a target="_blank" title="<?php _e('Subscribe to this blog', 'ctn1'); ?>" href="<?php echo $feed; ?>"><?php _e('RSS 2.0', 'ctn1'); ?></a></li> </ul> <?php if ( is_category() ) { $cat = get_query_var('cat'); $child_cats = get_categories('child_of='.$cat); if ($child_cats) { $args = array( 'title_li' => '', 'echo' => 1, 'child_of' => $cat ); echo '<ul class="submenu">'; wp_list_categories($args); echo '</ul>'; } } ?> |
替换为
1 2 3 | <?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?> <div class="search"><?php include (TEMPLATEPATH . '/searchform.php'); ?></div> <div class="tags"><?php _e('Tags: ', 'ctn1'); ?><?php wp_tag_cloud('smallest=12&largest=12&number=20&orderby=count&unit=px'); ?></div> |
修改style.css以支持二级导航(不支持IE6.0)
查找代码
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | #nav { margin: 0 auto 10px; width: 940px; background: #D3EAF0; overflow: hidden; } #nav .menu { height: 35px; line-height: 35px; background: #1A4963; font-size: 14px; overflow: hidden; } #nav .menu li { float: left; margin-left: 15px; padding: 0 10px; display: inline; } #nav .menu li a { color: #FFF; } #nav .menu li a:hover { text-decoration: none; } #nav .menu li.cat-item { margin-left: 0; } #nav .menu li.current-cat { background: url('images/bg.gif') repeat-x 0 1px; } #nav .menu li.current-cat a { color: #295B72; font-weight: bold; } #nav .menu li.search { float: right; _padding-top: 5px; } #nav .submenu { height: 35px; padding: 0 10px; font-size: 12px; overflow: hidden; } #nav .submenu li { float: left; margin: 8px 0 0; padding: 0 10px; border-right: 1px solid #295B72; display: inline; } #nav .submenu li a { color: #295B72; } #nav .submenu li a:hover { text-decoration: none; } |
替换为
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #nav { position: relative; margin: 0 auto 10px; width: 940px; background-color: #D3EAF0; } #nav .menu { height: 35px; line-height: 35px; background-color: #1A4963; font-size: 14px; } #nav .menu li { float: left; position: relative; padding: 0 15px; display: inline; } #nav .menu li a { color: #FFF; } #nav .menu li a:hover { text-decoration: none; } #nav .menu .current-menu-item { background: url('images/bg.gif') repeat-x 0 1px; } #nav .menu .current-menu-item a { color: #295B72; font-weight: bold; } #nav .menu li:hover > .sub-menu { display: block; } #nav .sub-menu { float: left; position: absolute; left: 0; top: 35px; width: 160px; background-color: #F8F8F8; border: 1px solid #D8D8D8; -moz-opacity: .9; opacity: .9; filter: alpha(opacity=90); display: none; z-index: 999; } #nav .sub-menu li { padding: 0; } #nav .sub-menu a { width: 130px; padding: 0 15px; display: block; text-align: left; } #nav .sub-menu .current-menu-item { background: none; } #nav .menu li:hover > .sub-menu a { color: #333; } #nav .menu li:hover > .sub-menu a:hover { background-color: #333; color: #FFF; } #nav .search { position: absolute; right: 10px; top: 5px; } |