Solved

change out naviation once logged in

Posted on 2011-09-04
15
420 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 108

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
 

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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

This article will shed light on the latest trends when it comes to your resume building needs. For far too long, the traditional CV format has monopolized the recruitment market.
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 set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now