Solved

change out naviation once logged in

Posted on 2011-09-04
15
419 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
Comment Utility
What menu system are you using?  Standard WordPress menus or something else?
0
 

Author Comment

by:COwebmaster
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
>> 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:COwebmaster
Comment Utility
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
Comment Utility
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
Comment Utility
actually, there is no header.php file.  there is functions.php but that didn't work.  Any suggestions?
0
 

Author Comment

by:COwebmaster
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Read about how to choose the best possible content marketing agency to suit your needs. Content marketing has become an integral part of running a successful tech business, so it is wise to be informed.
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 purpose of this video is to demonstrate how to Import and export files in WordPress. 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 : Click on Too…

762 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

7 Experts available now in Live!

Get 1:1 Help Now