header.php buttons – selected class
-
Why isn\’t this working? When i select \”My Stuff\” it doesn\’t change the button to the selected class color.
<li<?php if ( bp_is_page( \'members/\'.$username.\'/mystuff/stuff-home\' ) ) {?> class=\"selected\"<?php } ?>><a href=\"<?php echo get_option(\'home\') ?>/<?php echo \'members/\'.$username.\'/mystuff/stuff-home\' ?>\" title=\"<?php _e( \'My Stuff\', \'buddypress\' ) ?>\"><?php _e( \'My Stuff\', \'buddypress\' ) ?></a></li>
-
anyone have an idea?
I have this problem. I even wrote new buttons from scratch with unique id’s and still the selected css attribute would not work.
If I remember correctly this is a RC1 issue that was fixed someplace along the way in trunk. Lots of changes above rev 1303. Heads up.
thanks for the input guys. I am currently on r1241, so maybe that is the issue. weird thing is, I did this fine on another button, but this one doesn\’t seem to want to work.
here is the working button:
<li<?php if ( bp_is_page( 'chat' ) ) {?> class="selected"<?php } ?>><a href="<?php echo get_option('home') ?>/<?php echo chat ?>" title="<?php _e( 'Chat', 'buddypress' ) ?>"><?php _e( 'Chat', 'buddypress' ) ?></a></li>
Just taking a quick look at the bp code and it looks to me like the group of functions bp_is_* are designed to detect bp components. Not wp pages or whatever ‘chat’ is.
would the fix be to change the ‘budypress’ to ‘wordpress’
The ‘buddypress’ you are talking about is the translation text domain.
BeLogical – do you have a link to view your site? It could be as simple as a missing CSS rule for the “selected” class, meaning the PHP code is working fine in the theme but the selected element isn’t getting any specific styles.
I added regular links with no php and the selected class just does not work. It’s like something is saying do not use this class. If I have the normal links that come with BP the selected class works fine but if I add my own links it does not work. Spent an entire day trying to figure out what is doing this and decide to just forget it and removed selected from BP nav.
i gave up and did it my own way i basically looked at the URL and checked to see if it matched, if so, then use the selected class, if not, then a dummy class. use if you like:
<?php
global $current_user;
$username = $current_user->user_login;
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "/";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"]."".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$currentURL = curPageURL();
if ( $currentURL == "http://domain.net/members/$username/mystuff/stuff-home" ) {
$dynamicClass = 'selected';
} else {
$dynamicClass = 'NOTselected';
}
?>
<li class="<?php echo $dynamicClass; ?>"><a href="<?php echo 'http://domain.net/members/'.$username.'/mystuff/stuff-home' ?>" title="<?php _e( 'My Stuff', 'buddypress' ) ?>"><?php _e( 'My Stuff', 'buddypress' ) ?></a></li>this makes my head hurt, is there an easier way to add pages to the nav and have the select class work?
Im looking for an easier way as well. Can’t find a solution.
all you have to do is copy/paste the code I included. then look at your links and change selected to $dynamicClass as the last line of code above illustrates.
Would this be posted to the header file or can the function be used in bp-custom.php? Thanks
i put it in the header.php
- The topic ‘header.php buttons – selected class’ is closed to new replies.