The MU forums have moved to WordPress.org

Recent Postings on homepage w/post content (13 posts)

  1. nuprn1
    Member
    Posted 17 years ago #

    After seeing a few other examples of just pulling out the recent blogs by querying the wp_blog table. I wanted a bit more that showed the actual postings for each blog user.

    Not being experience whatso-ever in PHP/Perl, I tried to take crack at it anyways... Much more needs to be changed but this is a good starting point.

    If someone knows what they are doing, please update the code and post it here but here is what I have started with:


    <?php
    //What blogs where last updated, lets grab a bunch at first.
    $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE domain!='dubblogs.com' AND 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 = "wpdub_".$blog."_options";
    $blogPostsTable = "wpdub_".$blog."_posts";
    $blogCatTable = "wpdub_".$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 guid != '' ORDER BY id DESC LIMIT 0,5");
    //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 wpdub_". $postresult[6] ."_options WHERE option_name='siteurl'");
    $blogname = $wpdb->get_col("SELECT option_value FROM wpdub_". $postresult[6] ."_options WHERE option_name='blogname'");
    ?>
    <div id="post-" class="item entry">
    <div class="itemhead">
    <h3><a>" rel="bookmark" title='Permanent Link to "<?php echo $postresult[1]; ?>"'><?php echo $postresult[1]; ?></a></h3>
    </div>
    <div class="itemtext">
    <?php echo substr($postresult[3], 0, 197);?>
    </div>
    <p class="details">
    <small class="metadata"><a>"><?php echo $blogname[0]; ?></a> | <a>#comments" class="commentslink" title="Comment on <?php echo $postresult[1]; ?>"><?php echo $postresult[4]; ?>�<span>comments</span></a> | <span class="tagdata">todo</span> | <span class="chronodata"><?php echo time_since(abs(strtotime($postresult[5] . " GMT")), time()); gt; ?> ago</span></small>

    </div>
    <?php } ?>

    What I liked to still complete:
    Strip html and limit characters
    use nicecategories for listing the tags used
    clean up the code, faster?

    You can see an example on my testing site:
    http://dubblogs.com

  2. samchng
    Member
    Posted 17 years ago #

    nuprn1, I like what you have done. :)
    But I can't seem to get it to work. I am having problems getting the nice time that you have to show.

  3. samchng
    Member
    Posted 17 years ago #

    Any idea of how to get blog post summary and headings with dates? Like what has been done above?

  4. skcsknathan001
    Member
    Posted 17 years ago #

    Is there a code to display Recent Comments for WPMU [sitewide]?

  5. Bruz
    Member
    Posted 17 years ago #

    Is there a code to display Recent Comments for WPMU [sitewide]?

    That would be great! Any progress yet?

  6. lunabyte
    Member
    Posted 17 years ago #

    Sitewide feed -> comments feed in an rss widget.

  7. Bruz
    Member
    Posted 17 years ago #

    Thank you, I should really have seen this plugin earlier araound here...

  8. lunabyte
    Member
    Posted 17 years ago #

    The search page is a wonderful tool.

  9. drmike
    Member
    Posted 17 years ago #

    Search is your friend. All bow down to the mighty search bar. :)

  10. lunabyte
    Member
    Posted 17 years ago #

    Or search.php :D

  11. Bruz
    Member
    Posted 17 years ago #

    Well, I've used the search...

    Which lead me to this topic where all my questions got solved :-)

  12. drmike
    Member
    Posted 17 years ago #

    ALL HAIL THE MIGHTY SEARCH!

    I gotta switch to decaf... :)

  13. bojsoom
    Member
    Posted 16 years ago #

    the code is not work :( ...

About this Topic