Skip to:
Content
Pages
Categories
Search
Top
Bottom

Creating a link to the member page


  • carinallc
    Participant

    @carinallc

    I’d like to create a link to the member’s homepage. Does anyone know of a function that would return that link? For example, “www.fubar.com/members/[username]”?

    Thanks

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

  • Greg
    Participant

    @rebootnow

    Here is what I do (in BP 1.0.3):

    function _profile_url( $login_name=0 ) {
    global $bp;

    /* if no login name is specified, use logged in user */
    if ($login_name) {
    $url = $bp->root_domain . '/members/' . $login_name . '/profile';
    } else {
    $url = $bp->loggedin_user->domain . 'profile';
    }

    return $url;
    }


    carinallc
    Participant

    @carinallc

    Wow, hey thank you for responding! So, would I add this to the functions.php and then call it as:

    <?php _profile_url(); ?>


    Greg
    Participant

    @rebootnow

    Yes. That will give you the profile URL for the currently logged in member. But if all you want is a link to the currently logged in user, then you could use the bp_loggedinuser_link() tag. Note that this returns a LINK (i.e. <a href=”… etc.) and not just a URL. Just put…

    <?php bp_loggedinuser_link(); ?>

    …in your template where you want the link.

    If you do call my _profile_url() above to get the URL for a specific user, then note that you must provide the login name. So it depends what you have to begin with. Let’s say you have the user ID, then you need to get the login name as follows:

    $user = get_userdata( $user_id );
    $url = _profile_url( $user->user_login );

    And while we’re at it, if you want the URL for the displayed user, you can get it using…

    global $bp;
    return $bp->displayed_user->domain;


    porkchops1987
    Member

    @porkchops1987

    @Greg thank you so much. something so simple but so useful when creating our own templates. I dont know if you still participate in these forums but thanks nonetheless.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Creating a link to the member page’ is closed to new replies.
Skip to toolbar