Skip to:
Content
Pages
Categories
Search
Top
Bottom

header.php buttons – selected class


  • 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)

  • belogical
    Participant

    @belogical

    anyone have an idea?


    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.


    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.


    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>


    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.


    modemlooper
    Moderator

    @modemlooper

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


    Burt Adsit
    Participant

    @burtadsit

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


    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.


    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.


    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>


    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?


    Ezd
    Participant

    @ezd

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


    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.


    Kunal17
    Participant

    @kunal17

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


    belogical
    Participant

    @belogical

    i put it in the header.php

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘header.php buttons – selected class’ is closed to new replies.
Skip to toolbar