Solved

change out naviation once logged in

Posted on 2011-09-04
15
429 Views
Last Modified: 2012-06-27
I'm using wordpress and the s3member membership plugin.  When user logs in and I need to swap out the primary menu tabs with different ones.  Any clue how to go that? i'm using custom menu tabs now.  Someone suggested doing this:

"You could create a navigation using a Text widget with conditionals to change the entries depending on the user viewing the page."

but I'm referring to the primary menu tabs, not link inside a sidebar widget.

s2member plugin also has conditional shortcodes but not sure what to do

Any ideas experts?
0
Comment
Question by:COwebmaster
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 3
  • 2
  • +1
15 Comments
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 36480731
What menu system are you using?  Standard WordPress menus or something else?
0
 

Author Comment

by:COwebmaster
ID: 36481238
I'm using a custom menu in the dashboard although I can change that if your solution can make this work.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36481357
Not sure if this will help you unless you are fairly experienced in PHP, but the general design patterns for client authentication are illustrated in this article.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_2391-PHP-login-logout-and-easy-access-control.html

In a nuts hell, you detect authentication then make an if / else decision about which navigation block to show.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:COwebmaster
ID: 36481387
Okay so do I place those lines of code in my functions.php or some other file?  is there a menu.php file that handles all nav tabs?
0
 
LVL 5

Accepted Solution

by:
PragmatiCoder earned 500 total points
ID: 36481879
Easiest way to do this would be having two wordpress menus, one for visitors and another for logged in users.

<div id="main_menu">
<?php
if ( is_user_logged_in() ) {
    wp_nav_menu( array('menu' => 'Members menu' ));
} else {
    wp_nav_menu( array('menu' => 'Visitors menu' ));
}
?>
</div>

Open in new window


I don't know if you have to check access permissions, so this is just an example limited to display a menu for logged in users and a different menu for visitors

For further reference:
http://codex.wordpress.org/Function_Reference/is_user_logged_in
http://codex.wordpress.org/Function_Reference/wp_nav_menu
And maybe:
http://codex.wordpress.org/Function_Reference/get_userdata
If you want to check the user roles and access level
0
 

Author Comment

by:COwebmaster
ID: 36481921
okay, that makes sense but which php page do I place that on?  Also, how would I create two seperate menus using the custom menu feature in wp?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 36482009
>> but which php page do I place that on?

Most likely header.php.  That is where the theme usually has the menus

>> how would I create two seperate menus using the custom menu feature in wp?

Under Appearance | Menus, there is a + icon next to all currently defined menus.  Clicking it adds a new, blank menu.
0
 

Author Comment

by:COwebmaster
ID: 36482018
okay so if create two new custom menus called preloginmenu and postloginmenu, would the code be like this?

<div id="main_menu">
<?php
if ( is_user_logged_in() ) {
    wp_nav_menu( array('menu' => 'postloginmenu' ));
} else {
    wp_nav_menu( array('menu' => 'preloginmenu' ));
}
?>
</div>

Does that look correct?
0
 
LVL 70

Expert Comment

by:Jason C. Levine
ID: 36482036
Should be about right.  You will need to check your existing theme to make sure the div is named main_menu but otherwise that is correct.
0
 

Author Comment

by:COwebmaster
ID: 36482048
actually, there is no header.php file.  there is functions.php but that didn't work.  Any suggestions?
0
 

Author Comment

by:COwebmaster
ID: 36482076
it uses the Genesis framework from studio press theme.  I did find this and I think it has our answer in it:

add_filter('genesis_nav_items','follow_icons',10,2);
add_filter('wp_nav_menu_items','follow_icons',10,2);
function follow_icons($menu, $args) {
    $args = (array)$args;
    if ( $args['theme_location'] != 'primary' )
        return $menu;
    $follow = '<li id="follow">Follow: <a rel="nofollow" class="rss" href="'.get_bloginfo('rss_url').'"><img src="'.get_bloginfo('stylesheet_directory').'/images/feed.png" /></a> <a rel="nofollow" class="twitter" href="'.esc_url( 'http://twitter.com/' .genesis_get_option('nav_extras_twitter_id') ).'"><img src="'.get_bloginfo('stylesheet_directory').'/images/twitter.png" /></a></li>';
    return $menu.$follow;
 
}

How would we incorporate what you have into the above to make it display the other custom menu called postlogin that I made?
0
 

Author Comment

by:COwebmaster
ID: 36482170
PragmatiCoder, The menu tabs are appearing at the top of the page, not in the menu nav bar where it should be.

<div id="nav">
<?php
if ( is_user_logged_in() ) {
wp_nav_menu( array( 'menu' => 'postlogin' ) );
} else {
wp_nav_menu( array( 'menu' => 'prelogin' ) );
}
?>
</div>

What am I missing? Here is the link: http://membersmix.seozones.com/
0
 
LVL 5

Expert Comment

by:PragmatiCoder
ID: 36484161
If there's no header, you are using a child theme.

I checked the link and i don't see the error
0
 

Author Comment

by:COwebmaster
ID: 36484978
Hi there PragmatiCoder, it's a child theme using the Genesis framework from Studio Press.

Let me add it back in so you can see.
0
 

Author Closing Comment

by:COwebmaster
ID: 36490269
ok, I had to disable the primary menu bar from the theme settings, then use a plugin called simple hooks to get this to work.  Thanks PragmatiCoder!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The viewer will learn how to dynamically set the form action using jQuery.

687 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question