Solved

change out naviation once logged in

Posted on 2011-09-04
15
423 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
  • 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 109

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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

856 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