WordPress.org

Ready to get started?Download WordPress

Forums

WordPress MU Sitewide Tags Pages
Displaying Blogname in Sitewide Post Headlines (12 posts)

  1. member11
    Member
    Posted 3 years ago #

    Hi,
    I'm trying to work out a way to display the blog/site name above the post title on the home page my 'global tags' blog.

    This way I can differentiate where each post has originated from when viewed in the aggregated sitewide view.

    I tested this code:
    echo '<div id="blog_name"> ' . get_bloginfo ( 'name' ) . ' </div> ';
    but that displays the blogname for the 'global tags' blog and not the source of the content.

    thanks for your help.

    Paul

    http://wordpress.org/extend/plugins/wordpress-mu-sitewide-tags/

  2. David Sader
    Member
    Posted 3 years ago #

    Here's what I have, (since blogid is in postmeta with this plugin):

    <?php
    $org_blog_id = get_post_meta ($post->ID, 'blogid', true);
    if($org_blog_id) {
    $blog_details = get_blog_details($org_blog_id);
    echo '  from <a href="' . $blog_details->siteurl . '">' . $blog_details->blogname . '</a>';
    }
    ?>
  3. member11
    Member
    Posted 3 years ago #

    Thanks David.

    That may work - although not for me yet.

    I'm actually trying to blend it in with a custom-function using Thesis theme. I'll be asking there as well.

    Here's what I've been working with so far:

    function my_teaser_byline() {
        global $thesis_design;
        $date_formats = thesis_get_date_formats();
        $use_format = ($thesis_design->teasers['date']['format'] == 'custom') ? $thesis_design->teasers['date']['custom'] : $date_formats[$thesis_design->teasers['date']['format']];
        echo '<div id="blog_name"> ' . get_bloginfo ( 'name' ) . ' </div> ';
        echo '<abbr class="teaser_date published" title="' . get_the_time('Y-m-d') . '">' . get_the_time($use_format) . '</abbr>  |  ' . "\n";
            $categories = get_the_category();
        echo '<a class="teaser_category" href="' . get_category_link($categories[0]->cat_ID) . '">' . $categories[0]->cat_name . '</a>' . "\n";
    }
    add_action('thesis_hook_before_teaser_headline', 'my_teaser_byline');

    If there is a way to blend your solution in with what I have here then it would be great - and even better would be if the blogid also linked back to the particular blog. :)

    thanks for your help.

    Paul

  4. David Sader
    Member
    Posted 3 years ago #

    In order to get the $post->ID, you may have to global $post. Or you could use get_the_id()

    $org_blog_id = get_post_meta(get_the_id(), 'blogid', true);

  5. member11
    Member
    Posted 3 years ago #

    Thanks David.

    I'm not the coding type...

    Can you please show me how to re-write that back into the function above.
    i.e. is replacing echo '<div id="blog_name"> ' . get_bloginfo ( 'name' ) . ' </div> ';
    with $org_blog_id = get_post_meta(get_the_id(), 'blogid', true);
    going to be enough?

  6. David Sader
    Member
    Posted 3 years ago #

    function my_teaser_byline() {
        global $thesis_design;
        $date_formats = thesis_get_date_formats();
        $use_format = ($thesis_design->teasers['date']['format'] == 'custom') ? $thesis_design->teasers['date']['custom'] : $date_formats[$thesis_design->teasers['date']['format']];
    
    //begin blend
    $postid = get_the_id();
    $org_blog_id = get_post_meta( $postid, 'blogid', true);
    if($org_blog_id) {
    $blog_details = get_blog_details($org_blog_id);
    echo '<div id="blogname-' . $postid . '">  from <a href="' . $blog_details->siteurl . '">' . $blog_details->blogname . '</a></div> ';
    }
    //end blend
    
        echo '<abbr class="teaser_date published" title="' . get_the_time('Y-m-d') . '">' . get_the_time($use_format) . '</abbr>  |  ' . "\n";
            $categories = get_the_category();
        echo '<a class="teaser_category" href="' . get_category_link($categories[0]->cat_ID) . '">' . $categories[0]->cat_name . '</a>' . "\n";
    }
    add_action('thesis_hook_before_teaser_headline', 'my_teaser_byline');
  7. member11
    Member
    Posted 3 years ago #

    thanks David. That worked perfectly - almost :)

    Only problem is that the <div id="blogname- is pulling in the post id instead of the blog id.

    The blognames are displaying correctly but when I apply styling it matches it to the post id, meaning that other posts from the same blog aren't picking up the same styling.
    For example these two posts are from the same blog but the div starts as follows:
    <div id="blogname-46">
    <div id="blogname-38">

    Any ideas?

    Thanks again.

  8. David Sader
    Member
    Posted 3 years ago #

    Add a class to the div (so you don;t have more than one div on the page with the same id), but style the class

    <div id="blogname-' . $postid . ' class="blogname"">

    so all blognames get the same style.

    Then in your css change
    #blogname {foo;}
    to
    .blogname {bar;}

  9. member11
    Member
    Posted 3 years ago #

    really appreciate your time on this David.

    I'm actually wanting different styling for each blog though rather than the same style for each.

    Any ideas? Thanks again.

  10. David Sader
    Member
    Posted 3 years ago #

    Sorry, I know no way to dynamically render unique styles for potentially 100s of different blognames in a css stylesheet. If the div is a blogname, all blogname divs get same style is what I have. Not sure what you are after. But you do have blognames for each post title now.

    Now, if all posts from the same blog were aggregated within the same div on the tags page, sure. But you would need to get multiple loops to query posts from one blog at a time.

    ie on the tags blog adding

    query_posts('meta_key=blogid&meta_value=63');

    before the start of the loop will return posts only from blog 63.

  11. member11
    Member
    Posted 3 years ago #

    ok. i think i'll leave it there then. thanks very much for your help.

  12. jw60610
    Member
    Posted 2 years ago #

    I know it's been ten months since you guys have visited this issue...

    David, your original code worked great, except it does not pull the blog name for the parent blog (I should mention I'm using Sitewide tags to display all the posts in a loop on the main theme).

    Any ideas?

    I does display all of the other blog names.

    Thanks so much.

    J

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic