Skip to:
Content
Pages
Categories
Search
Top
Bottom

header.php buttons – selected class

  • Avatar of BeLogical
    BeLogical
    Participant

    @belogical

    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>

Viewing 15 replies - 1 through 15 (of 15 total)
  • Avatar of BeLogical
    BeLogical
    Participant

    @belogical

    anyone have an idea?

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    I have this problem. I even wrote new buttons from scratch with unique id’s and still the selected css attribute would not work.

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    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.

    Avatar of BeLogical
    BeLogical
    Participant

    @belogical

    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>

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    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.

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    would the fix be to change the ‘budypress’ to ‘wordpress’

    Avatar of Burt Adsit
    Burt Adsit
    Participant

    @burtadsit

    The ‘buddypress’ you are talking about is the translation text domain.

    Avatar of Lance Willett
    Lance Willett
    Participant

    @lancewillett

    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.

    Avatar of @modemlooper
    @modemlooper
    Moderator

    @modemlooper

    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.

    Avatar of BeLogical
    BeLogical
    Participant

    @belogical

    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>

    Avatar of Plunderpat808
    plunderpat808
    Participant

    @plunderpat808

    this makes my head hurt, is there an easier way to add pages to the nav and have the select class work?

    Avatar of Ezd
    Ezd
    Participant

    @ezd

    Im looking for an easier way as well. Can’t find a solution.

    Avatar of BeLogical
    BeLogical
    Participant

    @belogical

    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.

    Avatar of Kunal17
    Kunal17
    Participant

    @kunal17

    Would this be posted to the header file or can the function be used in bp-custom.php? Thanks

    Avatar of BeLogical
    BeLogical
    Participant

    @belogical

    i put it in the header.php

Viewing 15 replies - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.