WordPress 技巧:给每个页面都设置不同的菜单

做项目总是有一些很奇怪的要求,比如有些客户需要给每个页面设置不同的菜单,但是这些总是难不倒 WordPress:


prefix}postmeta WHERE meta_key = 'nav_menu';";
$nav_menus = $wpdb->get_col($sql);

if($nav_menus){
foreach ($nav_menus as $nav_menu){
if($nav_menu){
register_nav_menu( $nav_menu, $nav_menu);
}
}
}
}

add_action('save_post', 'wpjam_save_nav_menu_options');
function wpjam_save_nav_menu_options($post_id){
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
update_post_meta($post_id, 'nav_menu',$_POST['nav_menu']);
}

function wpjam_nav_menu_options(){
global $post;
if($_REQUEST['nav_menu']){
$nav_menu = $_REQUEST['nav_menu'];
}else{
$nav_menu = get_post_meta($post->ID, 'nav_menu', true);
}
?>