Skip to:
Content
Pages
Categories
Search
Top
Bottom

Testing to see if current page is profile page


  • Tracedef
    Participant

    @tracedef

    I’m using the code below to insert a menu link to user’s profile if they are logged in and to give it a “selected” class. It works, but the link is chosen as selected even when it is not on the members profile page, it is “selected” on every page…

    Anyone have any ideas on what I would I add to test “if current page is profile page” to THEN add the “selected” class?

    Thanks!!!

    <?php if ( is_user_logged_in() ) {
    if ( strpos($_SERVER['REQUEST_URI'], "/members/{$current_user->user_login}/") !== false ) { ?>

    <li ><?php bp_loggedinuser_link () ?></li>
    <?php } else { ?>
    <li class="selected"><?php bp_loggedinuser_link () ?></li>

    <?php }
    } ?>

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

  • Burt Adsit
    Participant

    @burtadsit

    Not sure exactly what “if current page is profile page” means. You can check if the current user is in *their* profile with bp_is_home(). It returns true if the user is viewing their own profile. You can find out what user is being displayed with $bp->displayed_user->id


    Tracedef
    Participant

    @tracedef

    Thanks Burt, that did the trick!

    The clarify, this adds a menu link to user’s profile page when they are logged in using their name as the anchor text. Then it adds the “selected” class to dynamically highlight the link only when the user is on their profile page, otherwise there is no “selected” class and the link is not highlighted ….

    Thanks again.

    T

    Final Code:

    <?php if ( is_user_logged_in() ) {

    if ( bp_is_home()) { ?>

    <li class="selected"><?php bp_loggedinuser_link () ?></li>
    <?php } else { ?>
    <li ><?php bp_loggedinuser_link () ?></li>

    <?php }
    } ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Testing to see if current page is profile page’ is closed to new replies.
Skip to toolbar