WordPress.org

Ready to get started?Download WordPress

Forums

Want Primary Navigation to Change on Registered user Only Pages (21 posts)

  1. qmic76
    Member
    Posted 2 years ago #

    I'm building a member only site and I want to only have member pages navigation links in the primary nav visible after the user has logged in. Right now I have all the page links shown in the primary nav which is a problem. I'm using the Responsive Theme 1.4.9 and I see that there so some changes need to be done in the functions.php and header.php file
    I'll list my current code in those two files below, please help with the php code snippet to replace the default theme code as you did on similar post...

    http://wordpress.org/support/topic/want-primary-navigation-to-change-on-members-only-pages?replies=23#post-2822856

    functions.php code looks like this

    register_nav_menus(array(
    'top-menu' => __('Top Menu', 'responsive'),
    'header-menu' => __('Header Menu', 'responsive'),
    'sub-header-menu' => __('Sub-Header Menu', 'responsive'),
    'footer-menu' => __('Footer Menu', 'responsive')
    )
    );

    header.php code looks like this

    <?php wp_nav_menu(array(
    				    'container'       => '',
    					'menu_class'      => 'top-menu',
    					'theme_location'  => 'top-menu')
    					);
    				?>
            <?php } ?>

    Please help me

  2. vtxyzzy
    Member
    Posted 2 years ago #

    I don't think you need any changes to functions.php. Just create a new menu in Admin->Appearance->Menus. Assuming you call it 'Members', your header.php code would be like this:

    <?php if ( is_user_logged_in() ) {
       wp_nav_menu(array( 'container' => '',
          'menu_class' => 'member-menu',
          'menu'  => 'Members')
       );
    } else {
       wp_nav_menu(array( 'container' => '',
          'menu_class' => 'top-menu',
          'theme_location'  => 'top-menu')
       );
    }
    ?>
  3. qmic76
    Member
    Posted 2 years ago #

    Thanks for your help but I'm still a little confused.

    I've implemented the code to header.php. But I'm not sure what you mean about creating a "Member" menu. I go to appearance/menus/ then I created a menu called "Members" but what pages should I include the 'members' menu?

    The first time I created the 'members' menu after you suggested it, I only included the pages that should be seen by members once they are logged in (members and projects). When I reloaded and logged out to check it, it only shows "members and projects" in the primary nav even though I'm logged out when it should be showing 'about and register' and only show 'member and projects' after logging in. I'm confused, am I not making the menu correctly or should there more code to defect login status in header.php or even functions.php (I did not change anything in functions.php based on your first response). As of right now its not defecting the login status change to switch between the 2 navigation displays. Please help

  4. vtxyzzy
    Member
    Posted 2 years ago #

    The code I showed should show one menu when logged in and another when not logged in. Don't know why it isn't doing that.

    Each menu should include everything that you want to show for that menu, not just parts that should be added to the other menu.
    EDIT: Here is where I got that bit of code:

    http://desizntech.info/2011/02/wordpress-hacks-for-members-only-website/

    I changed it a bit so you do not need to modify functions.php. I used the 'menu' parameter instead of the 'theme_location' parameter.

  5. qmic76
    Member
    Posted 2 years ago #

    ok this is the complete header div code below you gave me nested, is there anything else I should change or take out?

    <div id="header">
    
            <?php if (has_nav_menu('top-menu', 'responsive')) { ?>
    
    	        <?php if ( is_user_logged_in() ) {
      				 wp_nav_menu(array( 'container' => '',
         				 'menu_class' => 'member-menu',
         				 'menu'  => 'Members')
       				);
    				} else {
      				 wp_nav_menu(array( 'container' => '',
         				 'menu_class' => 'top-menu',
          				'theme_location'  => 'top-menu')
       				);
    			}
    		?>
    
            <?php } ?>

    Then I made two menus named...
    "top-menu" that has "about and register" shown for nav links
    "members" that has "members and projects" shown for nav links
    Both of these menus I dragged/clicked the corresponding pages then I saved the menus to be in the header region of the page. I then created a "dummy user" to sign up on a different browser to be on the safe side.

    On first load/display..about and register is shown in primary nav, then when logging in with the "dummy user" login, it still displays "about and register" not switching to the members menu..what I'm missing or doing wrong? When I first tried your suggestion I only created the one 'members' menu and clicked on 'member and project' pages to be linked to that menu and that didn't work so I tried to create two menus and no luck..

  6. vtxyzzy
    Member
    Posted 2 years ago #

    This is just a guess, but try taking out the nesting.

  7. Tami
    Member
    Posted 2 years ago #

    I have a related but not exactly the same question. I have a genesis child themed site that has both English and French pages. I would like an English menu to be in the Primary Menu location when on English pages and French on the French. Under "menus" I can only chose one menu to appear (obviously) but is it possible to have 2 registered menus to the same location and have them page specific?

  8. vtxyzzy
    Member
    Posted 2 years ago #

    You will have better luck if you start your own thread rather than adding a different question to an old thread.

  9. Digital Raindrops
    Member
    Posted 2 years ago #

    You are missing the Theme Location for the members, add a new location and create a members menu assign the menu to the new theme location!

    In functions.php add the new location!

    'members-menu' => __('Members Menu', 'responsive'),

    In header.php based on twenty eleven child theme, make the location conditional!
    UNTESTED:

    <?php $location = is_user_logged_in() ? 'members-menu' : 'top-menu'; ?>
    <?php wp_nav_menu( array( 'theme_location' => $location ) ); ?>

    HTH

    David

    EDIT: GRRRRR! another old topic posted an answer to, at least this one is not 9 months old!

  10. vtxyzzy
    Member
    Posted 2 years ago #

    @Digital Raindrops, there is no need for another Theme Location. If you look back to the code I first posted, it uses the 'menu' argument rather than the 'theme_location'. That code was tested and works.

  11. Digital Raindrops
    Member
    Posted 2 years ago #

    Hi vtxyzzy,
    More than one way to skin a cat, I thought it was a new and active topic I was answering with another solution, but it was historic ;(

    Theme Location is just another option, and the code is very tidy as the menu can be called whatever the website admin wants, I never hard code values myself, menu => 'members' is only ok when the admin knows what to call the menu, however if the website admin changes, or the the menu was deleted the members menu feature could then be lost!

    To me the 'Theme Location' solution is transportable across themes, if the theme location menu does not exists it will fall through to get_pages, it might help others looking for the same solution, this is not a critique of your solution, just my own opinion!

    David

  12. qmic76
    Member
    Posted 2 years ago #

    vtxyzzy,

    I tried taking out the nesting and I also added echo statements to see if the function is even being called and none of the echo statements would show, letting me know that the function is not being called at all. Are you sure I do not need to add any code to functions.php. I've already created the members menu which includes the links I want to show when users are logged in.

    Heres what my code looks like now..

    <?php if (has_nav_menu('top-menu', 'responsive')) { ; ?>
    
    	        <?php
    			$result = is_user_logged_in();
    			echo "RESULT IS $result<br />";
    
    			if ( is_user_logged_in() ) {
    				echo "I AM LOGGED IN";
      				 wp_nav_menu(array( 'container' => '',
         				 'menu_class' => 'member-menu',
         				 'menu'  => 'Members')
       				);
    				} else {
    				echo "NOT LOGGED IN";
      				 wp_nav_menu(array( 'container' => '',
         				 'menu_class' => 'top-menu',
          				'theme_location'  => 'top-menu')
       				);
    			}
    		?>

    I even created a top-menu along with member menu to see if that would work but it didn't so I went back just having the one members menu.

  13. vtxyzzy
    Member
    Posted 2 years ago #

    Do you see your message "RESULT IS xx" ?

    If not then the first if test is returning false. Try changing it to this (just temporarily for debugging):

    <?php if ( true || has_nav_menu('top-menu', 'responsive') ) { ; ?>
  14. qmic76
    Member
    Posted 2 years ago #

    Great i'm getting somewhere using the amended debugging code you provided. Now I can see the "RESULT IS..(not logged or logged in) based on log in status, but now it also created a duplicate menu above my main navigation in the (top-menu) space of the screen (upper right), which I don't want. The main navigation looks the same still all the links shown regardless of log in state, but when I log in or out the duplicate "top nav" it made does show only "member and project" in the menu when the user is logged in, I just want this to happen to my primary nav in the header...if your confused visit my site at mks76.com/wp/

  15. vtxyzzy
    Member
    Posted 2 years ago #

    NEVER EVER post a username and password on a public forum.

    REMOVE IT NOW!!

  16. qmic76
    Member
    Posted 2 years ago #

    Ok I remove it, It wasn't my admin account pass/loggin anyway. I just created that for you to see what I'm talking about if I didn't explain the issue properly, I'm sorry. Any insight?

    Right now i'm trying to remove the top-menu it created and have the function effect the member's menu so any help with that would be great thanks

  17. vtxyzzy
    Member
    Posted 2 years ago #

    In Admin->Appearance->Menus, assign the 'not logged in' menu to the location 'Header Menu'. Don't assign anything to 'Top Menu'.

  18. qmic76
    Member
    Posted 2 years ago #

    OK, this is what I have in the admin/appearance/menu before you told me that last response..

    It says my theme supports up to 4 menus under "Theme Location"
    For top-menu I have nothing in it
    For header-menu I have nothing in it
    For sub-header I have nothing in it
    For footer-menu I have nothing in it.

    Now remember the 'members' menu I created is not assigned to any theme location at this point which is why all the links show up, I would play it with..I would assign 'members' to Header-menu under theme locations in admin/appear/menus, but then only the two links I want to show when a member is logged in shows up even on log out state, so that's why I took 'members' out of header-menu and reverted back to all the links showing until I found a solution.

    The only menu I created per your request was 'members' from the earlier post, I did not create 'not logged in' menu, should I create one which would include all the not logged in links and then assign it the 'Header-menu'? And then if that is so, where do I assign the 'members'menu you had me make or do I leave it unassigned (not put in any of the 4 theme location menu spots)

  19. vtxyzzy
    Member
    Posted 2 years ago #

    Create the 'not logged in' menu (name it 'Not Logged In') and assign it in the 'Header Menu'.

    What you do with the Members menu depends on what you want to show.

    If you want the Members menu to appear in the 'Top Menu' location while the 'Not Logged In' menu appears in the 'Header Menu' location, put only the different things that Members should see, not everything. Assign it to the 'Top Menu' location. Your code will need to be changed to make this work.

    If you want the Members menu to replace the Not Logged In menu, create the Members menu and put in it everything that you want Members to see! Don't assign it to any location. Your existing code should then work.

  20. qmic76
    Member
    Posted 2 years ago #

    One last thing, I think the first initial code I gave you was the wrong part I showed you, I gave you the portion that related to the top-menu in header.php, when I should have gave you the portion that relates to the header-menu that is further down in the file. It looks like this..

    <?php wp_nav_menu(array(
    				'container' => '',
    				'theme_location' => 'header-menu')
    				);
    		?>

    I think I should have given you this first before you came up with a login/out snippet for me to use, and that's why I'm having all these issues it the top-menu showing up when I don't want one to begin with. I still will create a 'members' menu I know but if you get were I'm going with this, then post the ammend code snippet that you gave 3 weeks ago that will effect this code I showing now. Its just down dawned on me sorry. So i'll need that log in/log out solution you gave me but not for the top-menu code I gave you in the initial post but for this header-menu code I'm posting now, I think that's why its creating a top menu and all my results are showing in the top-menu area about the header menu, I'm I right...

  21. vtxyzzy
    Member
    Posted 2 years ago #

    OK - try this:

    if ( is_user_logged_in() ) {
       wp_nav_menu(array( 'container' => '',
          'menu_class' => 'member-menu',
          'menu'  => 'Members')
          );
    } else {
       wp_nav_menu(array( 'container' => '',
          'theme_location'  => 'header-menu')
          );
    }

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.