- Responsive Multi-Purpose Theme Framework! ›
- Forums ›
- Theme Support ›
- Account Menu in Top Menu Bar
Hi Ünsal,
I like the way you manage the login form and menu for logged users in your theme in the top menu bar. It’s simple and effective. Can you explain how to do it in your theme or which plugin in to use ?
Thanks in advance!
Well,
I wrote it but didnt polish it yet Means it not ready to release. Still if you want to play with it, here is code:
(Warning: Code will only work php5.3+ because of nameless function usage 😛 )
global $blog_id; if ( 1 == $blog_id) : add_filter( "wp_nav_menu_items", function ($items, $args){ $items .= firmasite_custom_bpmenu(); return $items; },10,2 ); add_action("wp_head", function(){ ?> <style type="text/css" media="screen"> .dropdown-form { padding: 15px; } </style> <script type="text/javascript"> jQuery(document).ready(function($){ jQuery("li.member-menu ul.dropdown-menu span").addClass("label label-info"); }); </script> <?php },11); add_action("wp_footer","firmasite_custom_bpmenu"); function firmasite_custom_bpmenu() { ob_start(); ?> <?php if ( !is_user_logged_in() ) { ?> <li class="dropdown member-menu"> <a class="dropdown-toggle" data-target="#" href="#"> <i class="icon-briefcase"> </i> <?php _e( 'Account', 'firmasite' ) ?> <b class="caret"> </b> </a> <ul class="dropdown-menu dropdown-form"> <li> <form name="login-form" id="login-form" action=" <?php echo site_url( 'wp-login.php' ) ?>" method="post"> <div class="input-prepend"> <span class="add-on"> <i class="icon-user"> </i> </span> <input type="text" name="log" id="user_login" value="" placeholder=" <?php _e( 'Username', 'firmasite' ) ?>" /> </div> <div class="input-prepend"> <span class="add-on"> <i class="icon-lock"> </i> </span> <input type="password" name="pwd" id="user_pass" value="" placeholder=" <?php _e( 'Password', 'firmasite' ) ?>" /> </div> <label for="rememberme" class="checkbox"> <input name="rememberme" type="checkbox" id="rememberme" value="forever" /> <?php esc_attr_e('Remember Me', 'firmasite'); ?> </label> <input type="submit" name="wp-submit" id="wp-submit" value=" <?php _e( 'Log In', 'firmasite' ) ?>"/> <?php if ( 'none' != bp_get_signup_allowed() && 'blog' != bp_get_signup_allowed() ) {?> <input class="btn btn-primary pull-right" type="button" name="signup-submit" id="signup-submit" value=" <?php _e( 'Create an Account', 'firmasite' ) ?>" onclick="location.href=' <?php echo bp_signup_page() ?>'" /> <?php }?> <input type="hidden" name="redirect_to" value=" <?php echo bp_root_domain() ?>" /> <input type="hidden" name="testcookie" value="1" /> <?php do_action( 'bp_login_bar_logged_out' ) ?> </form> </li> <?php } else { ?> <li class="dropdown member-menu"> <a class="dropdown-toggle" data-target="#" href="#"> <i class="icon-user"> </i> <?php echo bp_core_get_username( bp_loggedin_user_id() ); ?> <b class="caret"> </b> </a> <ul class="dropdown-menu"> <li> <?php firmasite_bp_adminbar_notifications_menu() ?> <?php bp_get_loggedin_user_nav() ?> <?php } ?> </ul> </li> <?php return ob_get_clean(); } function firmasite_bp_adminbar_notifications_menu() { if ( !is_user_logged_in() ) return false; echo ' <li id="bp-adminbar-notifications-menu" class="dropdown-submenu"> <a href="' . bp_loggedin_user_domain() . '">'; _e( 'Notifications', 'buddypress' ); if ( $notifications = bp_core_get_notifications_for_user( bp_loggedin_user_id() ) ) { ?> <span> <?php echo count( $notifications ) ?> </span> <?php } echo ' </a>'; echo ' <ul class="dropdown-menu">'; if ( $notifications ) { $counter = 0; for ( $i = 0, $count = count( $notifications ); $i < $count; ++$i ) { $alt = ( 0 == $counter % 2 ) ? ' class="alt"' : ''; ?> <li <?php echo $alt ?>> <?php echo $notifications[$i] ?> </li> <?php $counter++; } } else { ?> <li> <a href=" <?php echo bp_loggedin_user_domain() ?>"> <?php _e( 'No new notifications.', 'buddypress' ); ?> </a> </li> <?php } echo ' </ul>'; echo ' </li>'; } endif;
thank you for this code, I liked it and would implement it to but i dont know where this code has to be copied and to which directory so that it works flawlessly.
Please help
even if i use it in a child theme where exactly do I have to add the above code ?
Its an opening menu. When you hover on it, its opening and shows you a menu that includes link to profile too. First menu item is not clickable
i really tried to open it as any “drop down menu” but it didn’t open any thing
just redirected me to http://mysite-name/#
may it want to add jquery.js file and call it !!
Seriously this menu button is not designed for clicking. It was there for hovering and showing sub-menu. You have codes, you can change this. I cant help you for every customization.
Hello Unsal,
I also would like to add the Account Menu in Top Menu Bar but I have some problems.
I describe what I did:
1. I first created my top menu
2. I then created the child theme (firmasite-child)
3. I created the file “functions.php” in the newly created child theme directory
4. I copied your code above (I added “<?php” in the first line ) in the file “functions.php”
5. I saw the resulting page like this:
5.1 the items (the ones I previously created) of my menu are not visible in the menu bar
5.2.On the left side of the menu bar I see the icon of the Username, preceded by a circle, and that’s it.
If I delete the content of the “functions.php” the page returns my initial top menu correctly.
My version of php is 5.3.3
I thought there were some problems in the syntax and I checked the code with this:
It gave me these results:
– Error: There is 1 line with a typo in a php code declaration: ?>>
– PHP Syntax Check: Parse error: syntax error, unexpected T_FUNCTION in your code on line 5
add_action(“wp_head”, function(){ ?>
At this point, I didn’t know what to do.
I’m not familiar with php therefore it could be something simple that I cannot see.
Maybe you could just point me to where the problem could be, and I can try to find out further.
Many thanks in advance,
Gaia
As i said, this code is not suits for everyone and didnt published officially tbh. You are getting an error in there but probably your debug is closed so you cant see it. Basically this code requires BuddyPress plugin.
Thanks Unsal,
As soon as I added the BuddyPress plugin it worked smoothly
I’ll have some other questions related to how to modify the submenu (e.g., rename the sub-menu items, add new sub-menu items) but I’ll do the best first to solve it on my own.
Have a nice day,
Gaia
You must be logged in to reply to this topic.