WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Alternate Menus (20 posts)

  1. Chaotik804
    Member
    Posted 2 years ago #

    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://wordpress.org/support/topic/alternative-menu-for-logged-in-users?replies=11

  2. Marventus
    Member
    Posted 2 years ago #

    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's header.php file.
    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's functions.php.
    If you are still unsure about how to proceed, post the name of your theme and I'll give you more directions.

    Cheers!

  3. Chaotik804
    Member
    Posted 2 years ago #

    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

  4. Marventus
    Member
    Posted 2 years ago #

    No pb.
    In Magzimus 1.0 version, the code IS located in the header.php file, 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_menu to whatever name you desire, but make sure it is consistent with the location registered in functions.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.

  5. Chaotik804
    Member
    Posted 2 years ago #

    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

  6. Marventus
    Member
    Posted 2 years ago #

    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!

  7. dsg257
    Member
    Posted 2 years ago #

    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-menu

    thanks

  8. Marventus
    Member
    Posted 2 years ago #

    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 from functions.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.

  9. dsg257
    Member
    Posted 2 years ago #

    thanks Marventus
    think i got it

    function 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

  10. Marventus
    Member
    Posted 2 years ago #

    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!

  11. dsg257
    Member
    Posted 2 years ago #

    Right understand most of this
    here is the code i have

    [Code moderated as per the Forum Rules. Please use the pastebin]

  12. Marventus
    Member
    Posted 2 years ago #

    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://wordpress.org" 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.

  13. dsg257
    Member
    Posted 2 years ago #

    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 up

    thanks

  14. dsg257
    Member
    Posted 2 years ago #


  15. Marventus
    Member
    Posted 2 years ago #

    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' ) );
    }
    ?>
  16. dsg257
    Member
    Posted 2 years ago #

    well u certianly helped me a lot
    thanks Marventus
    hope this helps others as well
    going to implement it
    thanks

  17. dsg257
    Member
    Posted 2 years ago #

    give support for 2 more menus
    ticked permission to run php code in exec-php
    Security Hole :- No user matching the query
    Executing PHP Code in Text Widgets :- all in members
    gave permission for all to execute php code

    put code in text widget
    only get widget title no navigation
    any ideas what it could be

    thanks

  18. dsg257
    Member
    Posted 2 years ago #

    php code not being executed tried
    <?php echo "This is the Exec-PHP 'Hello World'"; ?>
    in widget but does not show

  19. dsg257
    Member
    Posted 2 years ago #

    Your theme supports 4 menus. Select which menu appears in each location.

    doent say where the location is lets me provide a menu for each of the 4 menu locations but none are in the sidebar and the php in the widget does not show them up

  20. Marventus
    Member
    Posted 2 years ago #

    Hi,
    Sorry I didn't get back to you sooner: I just saw your posts.
    The echo code should be working if the permissions are well configured. Don't forget you need some sort of Role Manager to be able to turn on PHP execution for the users you desire. Otherwise, Exec-PHP will not work for sure.
    Once you make that properly set up, the menu should appear on your sidebar.
    Cheers!

Topic Closed

This topic has been closed to new replies.

About this Topic