前段时间使用inove主题,想给修改导航菜单同时显示页面和分类,在网上查了很多资料,在本机上实验终于实现了导航菜单里同时显示页面和分类,操作步骤为
第一步:给主题设置里添加一个选项:show all(意思就是同时显示页面和分类)
1,修改inove/functions.php在第220行找到:
<label>
<input type=”radio” value=”categories” <?php if($options[‘menu_type’] == ‘categories’) echo “checked=’checked'”; ?> />
<?php _e(‘Show categories as menu.’, ‘inove’); ?>
</label>
2,在下面添加:
<label>
<input value=”pages_and_categories” <?php if($options[‘menu_type’] == ‘pages_and_categories’) echo “checked=’checked'”; ?> />
<?php _e(‘Show All.’, ‘inove’); ?>
</label>
第二步:实现showall功能:
1,修改inove/templates/header.php在第30行找到:
<?php if($options[‘menu_type’] == ‘categories’) { wp_list_categories(‘title_li=0&orderby=name&show_count=0’); }
else { wp_list_pages(‘title_li=0&sort_column=menu_order’); }
?>
2,将上面的代码替换为:
<?php
if($options[‘menu_type’] == ‘categories’ || $options[‘menu_type’] == ‘pages_and_categories’) { wp_list_categories(‘title_li=0&orderby=name&show_count=0’); }
if($options[‘menu_type’] == ‘pages’ || $options[‘menu_type’] == ‘pages_and_categories’) { wp_list_pages(‘title_li=0&sort_column=menu_order’); }
?>
上面显示顺序是先分类再页面,如果你喜欢把页面放在分类前面那就把上面的代码换成:
<?php
if($options[‘menu_type’] == ‘pages’ || $options[‘menu_type’] == ‘pages_and_categories’) { wp_list_pages(‘title_li=0&sort_column=menu_order’); }
if($options[‘menu_type’] == ‘categories’ || $options[‘menu_type’] == ‘pages_and_categories’) { wp_list_categories(‘title_li=0&orderby=name&show_count=0’); }
?>
只要在INOVE主题选项里勾选”show all”,你的导航菜单就变成了分类和页面同时显示了。