Skip to:
Content

BuddyPress.org

Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#1244 closed defect (bug) (fixed)

ul#nav class="selected" and ul#bp-nav class="current" are mixing up

Reported by: 21cdb's profile 21cdb Owned by:
Milestone: 1.2 Priority: major
Severity: Version:
Component: Keywords: selected, current, css, nav, navigation, menu, reporter-feedback
Cc: jason_jm, email@…

Description

While developing a custom theme for buddypress 1.1 i moved

<?php if ( is_user_logged_in() ) : ?>
<ul id="bp-nav">
	<?php bp_get_nav() ?>
</ul>

from userbar.php into header.php. When Home in ul#nav is the "selected" page, "Profile" in ul#bp-nav also gets the class "current".

It's the same for "Groups" and "Blogs" as you can see on the attached images.

Attachments (3)

Bildschirmfoto 2009-10-17 um 17.10. | 00.44.40.png (12.8 KB) - added by 21cdb 15 years ago.
Home is the current page (class="selected"), but Profile also gets the class "current"
Bildschirmfoto 2009-10-17 um 17.10. | 00.45.04.png (12.6 KB) - added by 21cdb 15 years ago.
Groups directory is selected but also Groups on #bp-nav gets class="current"
Bildschirmfoto 2009-10-17 um 17.10. | 00.46.01.png (12.7 KB) - added by 21cdb 15 years ago.
Blogs directory is selected but also Blogs on #bp-nav gets class="current"

Download all attachments as: .zip

Change History (12)

@21cdb
15 years ago

Home is the current page (class="selected"), but Profile also gets the class "current"

@21cdb
15 years ago

Groups directory is selected but also Groups on #bp-nav gets class="current"

@21cdb
15 years ago

Blogs directory is selected but also Blogs on #bp-nav gets class="current"

#1 @johnjamesjacoby
15 years ago

Can't duplicate this on testbp.org or my test installations. Best guess is this is an issue with your custom theme or potentially mish-mashed BP files from previous versions.

Explaination...

The main nav uses something like...

if ( bp_is_page( BP_GROUPS_SLUG ) )

Where as the bp_get_nav/bp_get_loggedin_user_nav uses...

if ( $bp->active_components[$bp->current_component] == $nav_item['css_id'] ) {

They're comparing two different parts of the nav. At first I thought something like this could occur but since they test two different parameters I don't see how core functions would allow this to happen.

Not saying it's impossible, but I can't make it broken to find a fix.

Care to share your code here to verify?

#2 @DJPaul
15 years ago

  • Keywords reporter-feedback added

#3 @21cdb
15 years ago

  • Cc email@… added

Hey John James Jacoby, i missed ur reply.

I changed my navigation so that it doesn't match the screenshots exactly, but the error is still there. Please find my header.php code attached in which the "Home" Button AND the Profile Button gets a highlight when on Home Page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

	<head profile="http://gmpg.org/xfn/11">

		<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

		<title><?php bp_page_title() ?></title>

		<?php do_action( 'bp_head' ) ?>

		<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats -->

		<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />
		<link rel="shortcut icon" href="<?php bloginfo('stylesheet_directory')?>/favicon.ico" type="image/x-icon">
		<link rel="icon" href="<?php bloginfo('stylesheet_directory')?>/favicon.ico" type="image/x-icon">

		<?php if ( function_exists( 'bp_sitewide_activity_feed_link' ) ) : ?>
			<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> <?php _e('Site Wide Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_sitewide_activity_feed_link() ?>" />
		<?php endif; ?>

		<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> <?php _e( 'Blog Posts RSS Feed', 'buddypress' ) ?>" href="<?php bloginfo('rss2_url'); ?>" />
		<link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> <?php _e( 'Blog Posts Atom Feed', 'buddypress' ) ?>" href="<?php bloginfo('atom_url'); ?>" />

		<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
		
		<?php load_theme_textdomain('envicom','wp-content/themes/bp-themes/bp-envicom/languages/');?> 
		<?php wp_head(); ?>

	</head>

	<body <?php body_class() ?>>
	
		<div id="wrapper-outline">	
		
		<?php do_action( 'bp_before_header' ) ?>		

		<div id="header">	
		
			<h1 id="logo"><a href="<?php echo get_option('home') ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php bp_site_name() ?></a></h1>
	
			
		<?php if ( is_user_logged_in() ) : ?>

					<ul id="nav">
						<li<?php if ( bp_is_page( 'home' ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?></a></li>
						<?php bp_get_nav() ?>
					</ul>
					
					<div id="logout-link">
					<?php bp_loggedin_user_avatar( 'width=19&height=19' ) ?><?php bp_log_out_link() ?>
					
					<?php do_action( 'bp_login_bar_logged_in' ) ?>
					</div>
					
		<?php else : ?>
					
					<ul id="nav">
				
				
				<li<?php if ( bp_is_page( 'home' ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?></a></li>
				
				<li<?php if ( bp_is_page( BP_HOME_BLOG_SLUG ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_HOME_BLOG_SLUG ?>" title="<?php _e( 'Blog', 'buddypress' ) ?>"><?php _e( 'Blog', 'buddypress' ) ?></a></li>

				
				<li<?php if ( bp_is_page( BP_FEATURES_SLUG ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_FEATURES_SLUG ?>" title="<?php _e( 'Features', 'envicom' ) ?>"><?php _e( 'Features', 'envicom' ) ?></a></li>

								
				

				<?php do_action( 'bp_nav_items' ); ?>
			</ul>
						
	<?php endif ?>


			<?php do_action( 'bp_header' ) ?>
	
		</div>
		
		<?php do_action( 'bp_after_header' ) ?>
		<?php do_action( 'bp_before_container' ) ?>
		
		
		<div id="container">
	
			<?php if ( !bp_is_blog_page() && !bp_is_directory() && !bp_is_register_page() && !bp_is_activation_page() && !bp_is_features_page() ) : ?>
		
				<?php locate_template( array( '/userbar.php' ), true ) /* Load the user navigation */ ?>
				<?php locate_template( array( '/optionsbar.php' ), true ) /* Load the currently displayed object navigation */ ?>
		
			<?php endif; ?>
			

#4 @21cdb
15 years ago

  • Cc email@… removed

I did another test with the newest version of trunk. Please take this code and save it as header.php into ur bp-default theme folder. Check the items of bp-nav and u can see that ul#nav items are highlighted with class="selected" as well as bp-nav items with class="current".

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes(); ?>>

	<head profile="http://gmpg.org/xfn/11">

		<meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php bloginfo('charset'); ?>" />

		<title><?php bp_page_title() ?></title>

		<?php do_action( 'bp_head' ) ?>

		<meta name="generator" content="WordPress <?php bloginfo('version'); ?>" /> <!-- leave this for stats -->

		<link rel="stylesheet" href="<?php bloginfo('stylesheet_url'); ?>" type="text/css" media="screen" />

		<?php if ( function_exists( 'bp_sitewide_activity_feed_link' ) ) : ?>
			<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> <?php _e('Site Wide Activity RSS Feed', 'buddypress' ) ?>" href="<?php bp_sitewide_activity_feed_link() ?>" />
		<?php endif; ?>

		<link rel="alternate" type="application/rss+xml" title="<?php bloginfo('name'); ?> <?php _e( 'Blog Posts RSS Feed', 'buddypress' ) ?>" href="<?php bloginfo('rss2_url'); ?>" />
		<link rel="alternate" type="application/atom+xml" title="<?php bloginfo('name'); ?> <?php _e( 'Blog Posts Atom Feed', 'buddypress' ) ?>" href="<?php bloginfo('atom_url'); ?>" />

		<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />

		<?php wp_head(); ?>

	</head>

	<body <?php body_class() ?>>
		
		<?php do_action( 'bp_before_search_login_bar' ) ?>	
		
		<div id="search-login-bar">
	
			<form action="<?php echo bp_search_form_action() ?>" method="post" id="search-form">
				<input type="text" id="search-terms" name="search-terms" value="" /> 
				<?php echo bp_search_form_type_select() ?>
	
				<input type="submit" name="search-submit" id="search-submit" value="<?php _e( 'Search', 'buddypress' ) ?>" />
				<?php wp_nonce_field( 'bp_search_form' ) ?>
			</form>
			
			<?php if ( is_user_logged_in() ) : ?> 
				<ul id="bp-nav">
					<?php bp_get_nav() /* Load the user navigation */ ?>
				</ul>

		
			<?php endif; ?>
			
			<?php do_action( 'bp_search_login_bar' ) ?>

		</div>

		<?php do_action( 'bp_after_search_login_bar' ) ?>			
		<?php do_action( 'bp_before_header' ) ?>		

		<div id="header">	
		
			<h1 id="logo"><a href="<?php echo get_option('home') ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php bp_site_name() ?></a></h1>
	
			<ul id="nav">
				<li<?php if ( bp_is_page( 'home' ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>" title="<?php _e( 'Home', 'buddypress' ) ?>"><?php _e( 'Home', 'buddypress' ) ?></a></li>
				<li<?php if ( bp_is_page( BP_HOME_BLOG_SLUG ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_HOME_BLOG_SLUG ?>" title="<?php _e( 'Blog', 'buddypress' ) ?>"><?php _e( 'Blog', 'buddypress' ) ?></a></li>
				<li<?php if ( bp_is_page( BP_MEMBERS_SLUG ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_MEMBERS_SLUG ?>" title="<?php _e( 'Members', 'buddypress' ) ?>"><?php _e( 'Members', 'buddypress' ) ?></a></li>

				<?php if ( function_exists( 'groups_install' ) ) : ?>
					<li<?php if ( bp_is_page( BP_GROUPS_SLUG ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_GROUPS_SLUG ?>" title="<?php _e( 'Groups', 'buddypress' ) ?>"><?php _e( 'Groups', 'buddypress' ) ?></a></li>
				<?php endif; ?>

				<?php if ( function_exists( 'groups_install' ) && ( function_exists( 'bp_forums_setup' ) && !(int) get_site_option( 'bp-disable-forum-directory' ) ) ) : ?>
					<li<?php if ( bp_is_page( BP_FORUMS_SLUG ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_FORUMS_SLUG ?>" title="<?php _e( 'Forums', 'buddypress' ) ?>"><?php _e( 'Forums', 'buddypress' ) ?></a></li>
				<?php endif; ?>
				
				<?php if ( function_exists( 'bp_blogs_install' ) ) : ?>
					<li<?php if ( bp_is_page( BP_BLOGS_SLUG ) ) : ?> class="selected"<?php endif; ?>><a href="<?php echo get_option('home') ?>/<?php echo BP_BLOGS_SLUG ?>" title="<?php _e( 'Blogs', 'buddypress' ) ?>"><?php _e( 'Blogs', 'buddypress' ) ?></a></li>
				<?php endif; ?>

				<?php do_action( 'bp_nav_items' ); ?>
			</ul>

			<?php do_action( 'bp_header' ) ?>
	
		</div>

		<?php do_action( 'bp_after_header' ) ?>
		<?php do_action( 'bp_before_container' ) ?>
		
		<div id="container">
	
			<?php if ( !bp_is_blog_page() && !bp_is_directory() && !bp_is_register_page() && !bp_is_activation_page() ) : ?>
		
				<?php locate_template( array( 'userbar.php' ), true ) /* Load the user navigation */ ?>
				<?php locate_template( array( 'optionsbar.php' ), true ) /* Load the currently displayed object navigation */ ?>
		
			<?php endif; ?>
			

#5 @jason_jm
15 years ago

  • Cc jason_jm added
  • Keywords selected current css nav navigation menu added
  • Resolution set to worksforme
  • Status changed from new to closed

I can verify that the stock themes are fine, there is not issue between the selections between the main nav and userbar nav. Thus I am closing the ticket.

This looks to be a custom user theme issue.

Recommend to the user that he/she post their code for their theme in which they've modified, i'm sure someone (like me) will help them out :-)

Note, it looks like your actively calling: bp_get_nav()
Note that:

  • bp_get_nav() calls bp_get_loggedin_user_nav()
  • bp_get_loggedin_user_nav() is called by userbar.php

So your script is calling bp_get_loggedin_user_nav() twice

This is what leads me to believe that it's a user custom theme issue.

Post your theme up and i'm sure people (including myself) will help you out, but I do believe the stock theme uses the functions properly.

#6 @jason_jm
15 years ago

btw, bp_get_nav() is also depreciated

#7 @21cdb
15 years ago

  • Cc email@… added
  • Resolution worksforme deleted
  • Status changed from closed to reopened

I removed bp_get_nav() from userbar.php so it isn't called twice. Thanks to your advice i replaced the depreceated bp_get_nav() with bp_get_loggedin_user_nav(), but the error still appears.

#8 @Jason_JM
15 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

I worked with 21cdb to clear this issue up off channel.

It was a custom theme issue.

Closing ticket.

#9 @Jason_JM
15 years ago

Dual css selection class comes from mixing two distinct menu's together.

*Userbar exists on it's own and has a 'default' 'profile' class as it expects to only be called within 'profile' pages and hence that being the initial selected menu option.

*Do not call userbar if your not showing user related information, aka at the home page or any related page.

Note: See TracTickets for help on using tickets.