Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How do I create a link that gets me back to Blog


  • Famous
    Participant

    @famous

    How do I create a link that takes me back from the BP profile to my original blog I signed into? I’ve tried

    
    <?php home_url( 'name' ); ?>
    <?php bp_root_domain(); ?>/<?php bp_blogs_root_slug(); ?>
    <?php echo bp_loggedin_user_domain() . bp_get_blogs_slug(); ?>
    <?php echo bp_get_loggedin_user_link(); ?>
    <?php bloginfo( $post->post_author ); ?>
    <?php site_url(); ?>
    

    Everything is a no go though :/

    Thanks

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

  • danbp
    Participant

    @danbp

    If you are on a multisite install, each profile has a tab containing a list of sites the member belongs too, so those link already exist.
    If you want such link elsewhere, you basically can use this.

    As you say nothing about where you want the link to be on a profile, i assume you want it explicitly showing on the profile header. Following snippet will accomplish that. I tested it on a MS install with 2 blogs (main site + 1 user blog).

    function my_link_to_blog() {
    
    if ( bp_is_user() ) {
    	$user_id = bp_displayed_user_id();	
    } else {
    	$user_id = bp_get_member_user_id();
    }
    
    	$blogs = get_blogs_of_user( $user_id );
    
    	if ( $blogs ) {
    		echo '<ul>';
    			foreach ( $blogs as $blog ) {
    			// exclude the main blog if a user signed to another one
    				if ( $blog->userblog_id != get_current_blog_id() ) { 
    					echo '<li>View my blog<a href="http://' . $blog->domain . $blog->path .'">' .  $blog->blogname . '</a></li>';
    				}
    			}
    		echo '</ul>';
    	}
    
    }
    add_action( 'bp_before_member_header_meta' , 'my_link_to_blog' ); 

    Add to bp-custom.php


    Famous
    Participant

    @famous

    Hello @danbp I used the code that you gave me, however it created a list of my blogs rather than pointing me back to the original blog I signed in with. Any ideas?

    Thanks


    danbp
    Participant

    @danbp

    Which WP install type are you using ? MS or single ? Give details please.


    Famous
    Participant

    @famous

    Its an MU install. After much thought — what you came up with is much better than what I was imagining — thanks for that. One more thing, is it possible to display those blogs only to the user and not other people who visit their profile?

    Thanks


    danbp
    Participant

    @danbp

    Yep ! Use fn bp_is_my_profile()

    For ex. something like if ( $blogs && bp_is_my_profile() ) {


    Famous
    Participant

    @famous

    Awesome thank you.
    Confirmed Resolved

Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
Skip to toolbar