Community Forums › Forums › Archived Forums › General Discussion › How do I make Primary Menu Conditional in News Theme ?
- This topic has 6 replies, 2 voices, and was last updated 10 years, 7 months ago by Strangeman.
-
AuthorPosts
-
June 4, 2013 at 11:28 am #44048StrangemanMember
I am trying to make a different Primary Menu appear if a user is logged in
I have registered a new menu type in functions.php
<code>
register_nav_menus( array( 'primary' => __( 'Primary Navigation', 'news' ), 'members' => __( 'Members Only Navigation', 'news' ), ) ); </code> and then I got stuck on where to apply the conditional code to make the members menu replace the primary menu. Or is that more complex than needs be and should I just be changing the Primary menu itself for a logged in user?
June 4, 2013 at 12:09 pm #44060rfmeierMemberHello,
Almost correct. Here is what I came up with;
If someone else has a more elegant method, feel free to speak up.
I hope this works.
Let me know how it turns out.
June 4, 2013 at 3:38 pm #44084StrangemanMemberHey Ryan,
Thanks for posting that code - it works really well ... except that there was no Primary menu if the visitor is not logged in
however when I changed the first couple of lines to this
<code>
// add the members menu through Genesis menu support
add_theme_support( 'genesis-menus', array(
'primary' => __( 'Primary Navigation', 'news' ),
'members' => __( 'Members Only Navigation', 'news' ),
) );</code>
It worked exactly as I wanted - thank you so much for your help!
June 4, 2013 at 7:15 pm #44092rfmeierMemberJune 20, 2013 at 12:01 pm #46903StrangemanMemberIs there a similar approach which I could use to populate a sidebar with widget(s) after a user has logged in ?
June 20, 2013 at 12:24 pm #46906rfmeierMemberWell,
If you have two sidebars, one for non-authenticated users and authenticated users, you could add your own custom genesis sidebar hook and fallback to the default one.
// remove the default sidebar callback remove_action( 'genesis_sidebar', 'genesis_do_sidebar' ); add_action( 'genesis_sidebar', 'custom_genesis_do_sidebar' ); /** * Callback for Genesis Framework 'genesis_sidebar' action. * * If the user is not logged in, display the default side, else * display the other (authenticated) sidebar, with the default as * a fallback. */ function custom_genesis_do_sidebar(){ // if the user is not logged in... if( ! is_user_logged_in() ){ // show fallback (non-authenticated) sidebar genesis_do_sidebar(); // exit the function return; } // display authenticated sidebar if ( ! dynamic_sidebar( 'auth-sidebar' ) ) { // fallback to default non-authenticated sidebar genesis_do_sidebar(); } }
This is what I came up with. I am sure there are probably a few ways to do this and maybe a plugin or two that could do the same.
Good luck.
September 6, 2013 at 2:05 am #61033StrangemanMemberHey Ryan, again, (and anyone else who might be interested)
Thanks for posting all that info back then, it produced a much simpler solution than having to install some overblown membersite plugin.
However .... just had a call from the owner of the first website I put this on to say that the menu has disappeared from her website ! At the moment it's looking like something in the upgrade to genesis 2.0.1 has produced this problem, so while I go about setting up a duplicate local site to test, I thought I'd post here and see whether you might know of a reason why 2.0.1 might have broken your code snippet (for the menu)
cheers Alan
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.