The MU forums have moved to

Sitewide Tags + get_blog_details (13 posts)

  1. existentialmedia
    Posted 14 years ago #

    I'm using Donncha's Sitewide Tags plugin to power a blog with posts from all blogs. I've been trying to figure out how to use the wpmu function get_blog_details to show the blogname for each post as directed by Donncha here. (Additionally, I would like to make a css class that would look like blog_5 to differentiate blogs.)

    I've tried figuring out a way to dynamically pass a blog_id into get_blog_details, but I haven't figured out a way to do this. One thing I've tried to do is use post_blog_id from the plugin to generate the blog_id, but since I don't really know a lot of PHP, I might not be doing the right thing.
    <?php get_blog_details( $post_blog_id ); ?>

    I've also tried using

    $details = get_active_blog_for_user(get_the_author_id());
    echo '<a href="' . $details->siteurl . '">' . $details->blogname . '</a>';

    suggested by dsader, but this doesn't work properly for me. It returns the default blog for a user, but this is often not the blog that the post is from because I have a large group blog that nearly all users post to.

  2. existentialmedia
    Posted 14 years ago #

    To give some specifics. The sitewide tags powered blog is here. I intend for the bars to be colored and have the correct title for blogs like on our homepage. (For the homepage I'm using a hacked up version of the ahp recent posts plugin.)

    So is there a way to get the blogname and/or blog_id with get_blog_details for a sitewide tags blog?

  3. existentialmedia
    Posted 14 years ago #

    Okay, this is resolved. I ended up altering the Sitewide Tags plugin like sirjoe. But I did it a little differently.

    $permalink = get_permalink( $post_id );
    on line 157 I added
    $org_blog_id = $wpdb->blogid;

    and after
    add_post_meta( $p, "permalink", $permalink );
    on line 183 I added
    add_post_meta ( $p, "blogid", $org_blog_id );

    Then I had to reimport the posts into the tags blog. To do put this into the Power Tools plugin (I did this for each blog because it seemed to choke after a certain number of posts)

    $posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_status = 'publish'" );
    if ( !empty($posts) ) {
    foreach ( $posts as $post ) {
    if($post != 1 && $post != 2)
    sitewide_tags_post($post, get_post($post));

    Now in my theme I can call the blog_id to generate css classes or the blogname. To call the blogname in my theme I used
    <?php $org_blog_id = get_post_meta ($post-> ID, 'blogid', true); $blog_details = get_blog_details($org_blog_id); echo $blog_details->blogname; ?>

    You can see the final product here.

  4. andrea_r
    Posted 14 years ago #

    You shoudl submit that change back to Donncha so he can decide if he wants to include it in the next version for everyone. :)

  5. existentialmedia
    Posted 14 years ago #

  6. sepp88
    Posted 14 years ago #

    @existetialmedia -> thanks for your helpful post, however i can't get it to work. i'm building a completly new blog from scratch, so i won't have to do the re-import part as you described. i replaced my site-wide tags plugin with your code, but i don't know where to put <?php $org_blog_id = get_post_meta ($post-> ID, 'blogid', true); $blog_details = get_blog_details($org_blog_id); echo $blog_details->blogname; ?>

    can you please help, it would be great if i could use your plugin for my wpmu-blog to indicate on my mainblog where the posts are coming from. either through colors like you did, or through a symbol or icon.

  7. existentialmedia
    Posted 14 years ago #

    Hi sepp99,

    I use that code here in my template to generate css classes.

    Inside of my loop on my index template I have:

    <h2 class="<?php $org_blog_id = get_post_meta ($post-> ID, 'blogid', true); $blog_details = get_blog_details($org_blog_id); echo 'title_'.$blog_details->blog_id; ?>"><?php the_title(); ?> – <?php $org_blog_id = get_post_meta ($post-> ID, 'blogid', true); $blog_details = get_blog_details($org_blog_id); echo $blog_details->blogname;?></h2>

    but you could use it anywhere

  8. sepp88
    Posted 14 years ago #

    thank you very much existentialmedia. i've now included this in my index.php and i already get the TITLE of my subblogs right besides the post-titles. COOL. however, it would be so great if you could tell me how you are assigning the colors to your different subblogs on your mainblog? do you define that in the css? how?

    thank you for your awesome code and for your help. for me the coolest thing would be, if i would be able to attach an image right above every post on my mainblog. e.g. if i have a subblog about music, every post in my mainblog should have an image right above it with for intance notes and guitars on it. is that possible? how would you do that?

    regard matt

  9. sepp88
    Posted 14 years ago #

    GOT IT!!! thanks very much!!!

  10. elemsee
    Posted 14 years ago #

    I have to thank you very much, I downloaded the edited plugin and it does pretty much exactly what I needed it to. Thanks to Donnacha, also. :)

  11. existentialmedia
    Posted 14 years ago #

    Don't thank me. I didn't do that much. It was all Donncha.

  12. existentialmedia
    Posted 13 years ago #

    Since Donncha and Ron updated the plugin, I updated the edited plugin.

  13. donncha
    Key Master
    Posted 13 years ago #

    Thanks, I just added that code to trunk!

About this Topic

  • Started 14 years ago by existentialmedia
  • Latest reply from donncha