The MU forums have moved to WordPress.org

I need the main blog page to display the most recent posts from other blogs (11 posts)

  1. bpetruzzo
    Member
    Posted 16 years ago #

    I need a way to display all of the most recent posts from sub-blogs on the main blog of my wordpressmu installation. I've been searching through the forums and google for a way to do this-- a plug in or something. I found two, "ah-recent-posts-mu" and "Recent Posts", both seem painfully slim on documentation and I'm just not enough of a coder to be able to figure it out. Is there some simpler way to pull this off that I'm missing some how?

    I'd like my installation's main blog to basically be self maintained by the updating of the sub blogs. Any ideas?

  2. dsader
    Member
    Posted 16 years ago #

    More to read at http://wiki.evernex.com/index.php?title=Wordpress_MU_sitewide_recent_posts_plugin

    Don't forget the "Sample call" for what to paste into your home.php
    ah_recent_posts_mu(5, 30, true, '<li>', '</li>');

  3. bwinn
    Member
    Posted 16 years ago #

    This is great but what if I dont want certain blogs to show up? Is there a way to filter them?

  4. mrhenry
    Member
    Posted 16 years ago #

    Find this part from the plugin listed above:

    $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE
    public = '1' AND archived = '0' AND mature = '0' AND spam = '0' AND deleted = '0' AND
    last_updated >= DATE_SUB(CURRENT_DATE(), INTERVAL $how_long DAY)
    ORDER BY last_updated DESC");

    and ad this: "AND blog_id != '%'" where "%" represents the blog id that you want to exclude

  5. bpetruzzo
    Member
    Posted 16 years ago #

    Kick me for not knowing, but what is a "sample call" and how do I insert one?

    Also, does the code from that page get pasted over the old code in the plugin or appended to the end? It looks like it should be overwritten.

  6. t3ch33
    Member
    Posted 16 years ago #

    I wound up using a solution from zimen in post http://mu.wordpress.org/forums/topic.php?id=948

    <?php
    //What blogs where last updated, lets grab a bunch at first.
    $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE public = 1 AND last_updated!='0000-00-00 00:00:00' ORDER BY last_updated DESC LIMIT 25");
    $tables = array();
    foreach ($blogs as $blog) {
    // we need _posts and _options tables for this to work
    $blogOptionsTable = "wp_".$blog."_options";
    $blogPostsTable = "wp_".$blog."_posts";
    $blogCatTable = "wp_".$blog."_post2cat";
    //add to array for later use
    $table = array ($blog, $blogPostsTable, $blogOptionsTable, $blogCatTable );
    $tables[] = $table; //push into tables
    }
    //now lets pull out 5 recent posts from each blog
    $postresults = array();
    foreach ($tables as $t) {
    $postitems = $wpdb->get_results("SELECT ID,post_title,guid,post_content,comment_count,post_date_gmt FROM $t[1] WHERE post_status = 'publish' AND post_type = 'post' AND guid != '' ORDER BY id DESC LIMIT 0,1");
    //push into array, had $postresults[] = $postitems;, but didn't work?
    foreach ($postitems as $postitem) {
    $col = array($postitem->ID,$postitem->post_title,$postitem->guid,$postitem->post_content,$postitem->comment_count,$postitem->post_date_gmt,$t[0]);
    $postresults[] = $col;
    }
    }
    function cmp($a,$b) {
    $at = strtotime($a[5]);
    $bt = strtotime($b[5]);
    if($at == $bt)
    return(0);
    if($at < $bt)
    return(1);
    else
    return(-1);
    }
    usort($postresults, 'cmp');
    foreach ($postresults as $postresult) {
    $siteurl = $wpdb->get_col("SELECT option_value FROM wp_". $postresult[6] ."_options WHERE option_name='siteurl'");
    $blogname = $wpdb->get_col("SELECT option_value FROM wp_". $postresult[6] ."_options WHERE option_name='blogname'");
    ?>
    <div class="entry">
    <table border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td><div class="entrytitle">
    <h2><a href="<?php echo $postresult[2]; ?>" rel="bookmark" title="Permanent Link to <?php echo $postresult[1]; ?>"><?php echo $postresult[1]; ?></a></h2>
    </div>
    <div id="entrybody">
    <?php
    $string = $postresult[3];
    $pos = strpos($string, "<!--more-->");
    if($pos === false) {
    echo $string;
    }else{
    echo substr($string, 0, $pos)."&nbsp;&nbsp;<a href=".$postresult[2] .">(More...)</a>";
    }
    ?>
    </div></td>
    </tr>
    </table>
    <div class="entrymeta">
    <div class="postinfo">
    <a href="<?php echo $siteurl[0]; ?>"><?php echo $blogname[0]; ?></a> | <a href="<?php echo $postresult[2]; ?>"><?php echo $postresult[4]; ?> comments &raquo; </a>
    </div>
    </div>
    </div>
    <?php } ?>

    And, if you want to use the other solution that you were asking about, what the poster meant by "Sample call" is that you have to include the request in home.php To test it, just copy/paste the following code wherever you want it to appear in your home.php page.

    ah_recent_posts_mu(5, 30, true, '<li>', '</li>');

    Be sure to also upload the plugin script to wp-content/plugins

  7. lunabyte
    Member
    Posted 16 years ago #

    Posting long code here doesn't help.
    If you need to post code - use a pastebin service like http://wordpress.pastebin.ca

  8. bwinn
    Member
    Posted 16 years ago #

    Does the plugin on the second post in this thread, show the title only or will the content display as well?

  9. bpetruzzo
    Member
    Posted 16 years ago #

    Thanks for all the suggestions folks. My biggest problem here is implimentation. Obviously people have figured out how to make it work, but I only know code well enough to tinker with what's already there.

    I would try this code in addition to the plugin:
    ah_recent_posts_mu(5, 30, true, '

  10. ', '
  11. ');

    but I'm not exactly sure where to put it. What file does it go into? Does it go into an existing php tag structure? If not, what should a new php tag structure look like?

    Thanks for the help folks. It's not easy being a php idiot.

  • bpetruzzo
    Member
    Posted 16 years ago #

    I've done some research and I managed to get the ma_recent_posts thing working, but it seems to be much too slim. I need it also to display the actual blog post. Or at least an introduction to it.

    Essentially what I need is for the main blog page to be a cumulative display of all of the sub-blogs. It looks like these options are going to kill me with formatting needs. Is there some other option anyone else has figured out?

  • t3ch33
    Member
    Posted 16 years ago #

    Did you read my post? That's exactly what I'm using on my site. It worked the first time without any tinkering at all. Just copy/paste into your theme's home page.

  • About this Topic