WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Mulisite - How to Get a Users Site/Blog URL (13 posts)

  1. myladeybugg
    Member
    Posted 1 year ago #

    In a multisite setup, when users are visiting a blog/site that is not theirs, I would like to display a link to "Visit My Blog" that takes them to that users "primary" blog.

    I am using WP 3.5 with buddypress installed.

    Currently I am using this:

    <a href="<?php $blog = get_active_blog_for_user( get_current_user_id() );
    $blog_url = $blog->domain?>">Visit My Blog</a>

    But this brings me to the users buddypress profile (domain.com/members/user) not their blog (domain.com/user).

  2. Let's break it out...

    <?php
    $blog = get_active_blog_for_user( get_current_user_id() );
    $your_url = $blog->domain;
    ?>
    <a href="<?php echo $your_url; ?>">Visit My Blog</a>
  3. myladeybugg
    Member
    Posted 1 year ago #

    Thanks for the response Mika! Unfortunately this takes me to a page not found.

    It takes me to blog.domain.com/members/user/blog.domain.com

    Where their blog is at blog.domain.com/user

  4. Part of that is you need an http:// in that a href. But...

    Hmm. It's echoing the blog DOMAIN, as it should. What does this do?

    <?php
    $blog = get_active_blog_for_user( get_current_user_id() );
    ?>
    <a href="http://blog.domain.com/<?php echo $blog; ?>">Visit My Blog</a>

    I'm assuming they're all on the same domain here.

  5. myladeybugg
    Member
    Posted 1 year ago #

    Didn't occur to me to add http:// :)

    Using your last code removes everything below the code on the page. Using your first code with the http:// brings me to the main blog on the multisite.

    So we are definitely closest with the first code it's just not picking up the user.

    So maybe something different where $blog=? Sorry, I am not too good with PHP otherwise I'd be more help.

  6. Using your last code removes everything below the code on the page.

    Huh.

    <?php
    $user_ID = get_current_user_id();
    $user_blog = get_active_blog_for_user( $user_ID );
    ?>
    <a href="http://blog.domain.com/<?php echo $user_blog; ?>">Visit My Blog</a>
  7. myladeybugg
    Member
    Posted 1 year ago #

    Ya it's weird. The last code did the same thing.

    Here's a before picture:
    http://i.imgur.com/v7Zs7.png

    And here's an after picture:
    http://i.imgur.com/W11DE.png

  8. myladeybugg
    Member
    Posted 1 year ago #

    I found this code:

    <?php
    if(is_user_logged_in()) {
    global $current_user;
      $blogs = get_blogs_of_user( $current_user->id );
         if($blogs) {
         	 foreach ( $blogs as $blog ) {
             echo '<li><a href="http://' . $blog->domain . $blog->path .'">' .  $blog->blogname . '</a></li>';
    		}
         }
    }
    ?>

    It does display the correct URL (yay!), but it only works for the logged in user and displays all users blogs; where I'm looking to only display the users primary blog.

    Here is the post: http://wordpress.org/support/topic/how-to-get-the-urlpath-of-current-users-site?replies=6

  9. Both images are the same. Where am I looking....?

    Does echo get_active_blog_for_user( get_current_user_id() ); do anything?

  10. myladeybugg
    Member
    Posted 1 year ago #

    Whoops! Here is the before: http://i.imgur.com/6edHv.png

    Let me try that code I'll get back to you.

  11. myladeybugg
    Member
    Posted 1 year ago #

    It removed everything below the member header also.

  12. Oooh.

    We're silly. Who's the 'current user' when viewing a page?

  13. myladeybugg
    Member
    Posted 1 year ago #

    Currently it is myladeybugg.

    But I want the "Visit My Blog" to be visible to all users and guests.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.