Set-up different Nav-bar
-
Hi all
I have a little problem. I’m using Theme Forest X and I would like to have different main menu depend on the pages. (So I need different nav-bar on each pages)
I ask them solution for that but they said it’s not sipported by the theme.
I search on Google and I found solution. It works well, very well actually except that the menu doesnt appear with the good style
It should be like
Link 1 Link 2 Link 3 link 4but appear like
*link 1
*link 2
*link 3
*link 4I copy the code here (Found on https://wpquestions.com/question/showChrono/id/8689)
So in my function php I added:
add_action( 'add_meta_boxes', 'ashu_add_custom_box' ); function ashu_add_custom_box(){ if ( function_exists('add_meta_box') ) { add_meta_box( 'page_custom_menu','page-menu', 'page_custom_menu_box', 'page', 'side','high'); } } function page_custom_menu_box(){ global $post; if ( metadata_exists( 'post', $post->ID, 'page_menu' ) ) { $menu_id = get_post_meta( $post->ID, 'page_menu', true ); } $entries = get_terms( 'nav_menu', array( 'hide_empty' => false ) ); echo '<select class="postform" id="page_menu" name="page_menu"> '; echo '<option value="">Select...</option> '; foreach ($entries as $key => $entry){ $id = $entry->term_id; $title = $entry->name; if ( $id == $menu_id ){ $selected = "selected='selected'"; }else{ $selected = ""; } echo"<option $selected value='". $id."'>". $title."</option>"; } echo '</select>'; } add_action('save_post', 'save_postdata'); function save_postdata( $post_id ) { global $post; if( !isset($_POST['page_menu']) ) return; $data = $_POST['page_menu']; if(get_post_meta($post_id, 'page_menu') == "") { add_post_meta($post_id, 'page_menu', $data, true); }elseif($data != get_post_meta($post_id, 'page_menu', true)) { update_post_meta($post_id, 'page_menu', $data); }elseif($data == "") { delete_post_meta($post_id, 'page_menu', get_post_meta($post_id, 'page_menu', true)); } }
And in my _nav-primary.php ( in “public_html/wp-content/themes/x/framework/views/global”)
I added:<?php if( is_page() && get_post_meta( $post->ID, 'page_menu', true )!='' ){ global $post; $menu_id = get_post_meta( $post->ID, 'page_menu', true ); wp_nav_menu( array( 'container_class' => 'menu-header', 'menu' => $menu_id ) ); }else{ //default menu wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); } ?>
I guess I just have to give the good style to my menu but I have no idea how to do it.
I hope you can help me with that.
thx a lot
- The topic ‘Set-up different Nav-bar’ is closed to new replies.