Alternate Menus
-
I have a site at http://www.theundustry.com, I am having trouble with conditionals. My theme supports 2 menu’s. A main menu and a top menu. I would like to be able to show a different menu on the top one depending on whether a user is logged in or not. I read a post earlier about this but could not figure out where to put the conditionals within my theme. I was able to create a 3rd menu but could not figure out the rest. I am using the Magzimus theme from themeforest. If anyone is willing to take a shot at this just let me know! Thanks in advance.
Here is the topic I was reading earlier on this
http://ww.wp.xz.cn/support/topic/alternative-menu-for-logged-in-users?replies=11
-
Hello there,
That thread you linked to addresses your exact same query.
Basically, if you want to be able to control and customize all your menus from the WP Admin Panel, you need to create an additional one, i.e., you need 3 menus total:
1. Top menu for logged-in users;
2. Top menu for visitors (non-logged-in users);
3. Main menu
Your conditional php statement should be placed where your theme calls the top menu, most likely in your theme’sheader.phpfile.
Finally, you need to identify in which file your theme is registering the nav menus, and add (register) a third one, most likely from your theme’sfunctions.php.
If you are still unsure about how to proceed, post the name of your theme and I’ll give you more directions.Cheers!
Thanks, I have located the register menus in functions but I do not see anything that deals with the wp nav menu in header, I guess I’ll have to go into each php file 1 by one till i discover it
No pb.
In Magzimus 1.0 version, the code IS located in theheader.phpfile, line 99:
<?php wp_nav_menu( array( 'theme_location' => 'primary_menu', 'fallback_cb' => 'fallback_menu' ) ); ?>
Maybe in 1.2 it is located elsewhere. What you need to do insert the conditional if statement before this line, like so:<?php if ( is_user_logged_in() ) { wp_nav_menu( array( 'theme_location' => 'primary_menu', 'fallback_cb' => 'fallback_menu' ) ); } else { wp_nav_menu(array('theme_location' => 'visitor_menu', 'fallback_cb' => 'fallback_menu' ) ); } ?>You can rename the location
visitor_menuto whatever name you desire, but make sure it is consistent with the location registered infunctions.php.
Once you do that, just create the new visitor menu in the Menu Editor and associate it to that new location, and you are set.Thank you so much you are a life saver, my problem was I was trying to edit the header from within the wordpress editor but as soon as I loaded it up in in dreamweaver it showed up! Really man thank you a bunch, I only got an hour of sleep before work last night trying to fix that, lol
You are welcome. I’m glad you were able to figure it out.
Please don’t forget to mark this thread as “solved” (if it is indeed solved, that is).
Good luck!have the same problem but wish to have a side menu created in custom menu
i am using the weaver theme which can be dificult to alter so any and all help would be great especially where to add the nav-menuthanks
Hi,
If what you want is to have 2 different nav menus in the sidebar and display either one based on whether or not the user is logged in, you need to:
1. Register your menus (or the additional ones) using register_nav_menus. This is usually done fromfunctions.php.
2. Create menus for the registered locations from the Admin Panel -> Appearance -> Menus.
3. Call your menus conditionally using wp_nav_menu, as per the example above, from either:
a. your sidebar.php file, before the the widget call. This will hardcode the menus in your sidebar and you won’t be able to move them around from WP Admin Panel.
b. your widgets, in which case you will need Exec-PHP (or any other plugin that allows you to run php code in your posts, pages, and widgets) and a capability manager plugin, such as Role Manager, to control which users and/or roles can run PHP scripts from those locations.That should cover it.
thanks Marventus
think i got itfunction code i understand wp_nav_menu <?php if ( is_user_logged_in() ) { wp_nav_menu( array( 'theme_location' => 'primary_menu', 'fallback_cb' => 'fallback_menu' ) ); } else { wp_nav_menu(array('theme_location' => 'visitor_menu', 'fallback_cb' => 'fallback_menu' ) ); } ?>[Please post code snippets between backticks or use the code button.]
i incert this code before the widget code in sidebar.php and it will select menu depending one criteria is this right
thanks
Yes, that is correct. In that case, you won’t be able to move the menu up and down as you would with a regular widget, but it will do the trick.
If you want a widget, then follow point 3.b.
Cheers!Right understand most of this
here is the code i have[Code moderated as per the Forum Rules. Please use the pastebin]
Hi,
You are not supposed to paste more than 10 lines of code in your posts as per the Forum Guidelines. When the code exceeds 10 lines, you are supposed to paste it on Pastebin. When it does not, you should put your code between back ticks, like so:
<a href="http://ww.wp.xz.cn" title="Some Link">Properly inserted code</a>As for your code, it needs to be placed after the opening php code tag (
<?php) and not after the closing tag (?>).Also, since you changed the names of your locations, make sure to update the wp_nav_menu arguments to reflect the new location names.
sorry for that here is the code
<script src=”http://pastebin.com/embed_js.php?i=zBeJX0us”></script>
using the weaver theme but just dont know where to incert the code into the sidebar.php
<script src=”http://pastebin.com/embed_js.php?i=q1AeaXCv”></script>
tried in various places but no luck menu does not show upthanks
Hi,
No worries about the code.
First, you need to locate this code in your functions.php file:// Weaver supports two nav menus register_nav_menus( array( 'primary' => __( 'Primary Navigation', WEAVER_TRANSADMIN ), 'secondary' => __( 'Secondary Navigation', WEAVER_TRANSADMIN ), ) );As you can see, the Weaver theme is already registering two menus. If you want to register two additional ones, simply add this part of your own code:
'main' => __('Main Menu', WEAVER_TRANSADMIN ), 'visitor' => __('Visitor Menu', WEAVER_TRANSADMIN )after the secondary menu call and before
) );.As for the menu call, I took a close look at the Weaver theme, and I think it might be a better idea to add the menus as widgets, since you have multiple sidebars where you could place the menu and that will translate into additional flexibility down the line.
In order to call the menus from a widget, install both plugins I recommended above (Role Manager and Exec-PHP) and follow all the instructions given.
Then, create a new text widget and paste this in the content window:<?php if ( is_user_logged_in() ) { wp_nav_menu( array( 'theme_location' => 'main', 'fallback_cb' => 'fallback_menu' ) ); } else { wp_nav_menu(array('theme_location' => 'visitor', 'fallback_cb' => 'fallback_menu' ) ); } ?>well u certianly helped me a lot
thanks Marventus
hope this helps others as well
going to implement it
thanks
The topic ‘Alternate Menus’ is closed to new replies.