Community Forums › Forums › Archived Forums › Design Tips and Tricks › How To Turn Navigation On & Off For Post & Pages
- This topic has 3 replies, 2 voices, and was last updated 9 years, 7 months ago by Veit.
-
AuthorPosts
-
September 2, 2014 at 7:33 pm #122514VeitMember
Hi guys,
I'm trying to set up a custom function on our child theme to enable and disable the primary and secondary navigation on a per post/per page basis.
I have these metaboxes set up:
/**
* Primary Navigation Turn Off Option
*/
$meta_boxes['primary_navigation_options'] = array(
'id' => 'primary_nagivation',
'title' => __( 'Disable Primary Navigation', 'cmb' ),
'pages' => array( 'post','page' ),
'fields' => array(
array(
'name' => __( 'Disable Top Navigatoin Next To Logo', 'cmb' ),
//'desc' => __( 'field description (optional)', 'cmb' ),
'id' => $prefix . 'dis_primary_navigation',
'type' => 'checkbox',
),
),
);/**
* Secondary Navigation Turn Off Option
*/
$meta_boxes['secondary_navigation_options'] = array(
'id' => 'secondary_nagivation',
'title' => __( 'Disable Primary Navigation', 'cmb' ),
'pages' => array( 'post','page' ),
'fields' => array(
array(
'name' => __( 'Disable Blue Lower Navigatoin', 'cmb' ),
//'desc' => __( 'field description (optional)', 'cmb' ),
'id' => $prefix . 'dis_secondary_navigation',
'type' => 'checkbox',
),
),
);In the theme functions I then have this:
//Remove Primary Navigation
remove_action( 'genesis_after_header', 'genesis_do_nav');
function show_hide_primary_navigation() {
$checkprimnav = get_post_meta( get_the_ID(), '_pvm_dis_primary_navigation', true );
if ( !empty($checkprimnav) && $checkprimnav === 'on' ) {
add_action( 'genesis_header_right', 'genesis_do_nav' );
}
}//Remove Secondary Navigation
remove_action( 'genesis_after_header', 'genesis_do_subnav');
function show_hide_secondary_navigation() {
$checksecnav = get_post_meta( get_the_ID(), '_pvm_dis_secondary_navigation', true );
if ( !empty($checksecnav) && $checksecnav === 'on' ) {
add_action( 'genesis_header', 'genesis_do_subnav' );
}
}=> why is this not working...?
Thanks,
VeitSeptember 3, 2014 at 2:25 am #122526Brad DaltonParticipantPlease do not duplicate posts.
Mark this as resolved and go back to your original post please http://www.studiopress.community/topic/custom-navigation-per-pagepost/
Also, please embed code using Github Gists.
Your code is broken and will break the site of anyone who copies and pastes in into a file. Thanks
September 3, 2014 at 8:06 am #122569VeitMemberI actually marked the other post as "resolved" before starting this one and just started a new one with the code here, so it's a cleaner separation of issues.
I should have done that right from the start, so my apologies.
Sorry for the code embed, I wasn't aware of that. My first time to paste code.
So, here is with Gist Hub code:
The code to create the checkbox in the WP backend:
https://gist.github.com/8e0723dd5f7d426a6601.git
And here is the code in the child functions:
https://gist.github.com/8e0723dd5f7d426a6601.git
Thanks for your help!
September 3, 2014 at 10:46 am #122609VeitMemberdamn it, Github... first time I'm using it, so sorry for the mess ups...
here is the correct WP backend code:
https://gist.github.com/anonymous/2de15e501b4e7a63c380
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.