The MU forums have moved to WordPress.org

Show last updated sites (22 posts)

  1. andrea_r
    Moderator
    Posted 16 years ago #

    I can't remember who we got the original code from, someone here in the forums, but we've been tweaking it without mercy. It hasn't been plugin-ified yet, but we're working on it and also on making it better. (we = me and my husband Ron)

    You can see here on our main page a list of the last ten sites updated in our network, with a link to that post.

    Here is a text file of what I put on our index page.
    (dang, couldn't link to a txt file on my server. Must tweak rewrite somewhere.)
    Here's the pastebin for it:
    http://pastebin.com/642490

    Hope that helps someone, and if so, I can continue to update this thread.

  2. andrewbillits
    Member
    Posted 16 years ago #

    hmm, would you mind if I added a bit of your code to my plugin:

    http://wpmudevorg.wordpress.com/project/List-All

    :)

  3. andrea_r
    Moderator
    Posted 16 years ago #

    Feel free. :)

    I think we use the List-All on our main page sidebar. Ron is the SQL genius in our house. I just make stuff look pretty. ;)

  4. samchng
    Member
    Posted 16 years ago #

    I got this from somewhere I don't remember, codes seems similar. Are there any difference?

    <h2>Last Updated</h2>
    <div class="comments">

      <?php
      $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE domain!='yourblog.com' AND last_updated!='0000-00-00 00:00:00' ORDER BY last_updated DESC LIMIT 10");
      foreach ($blogs as $blog) :
      // we need _posts and _options tables for this to work
      $blogOptionsTable = "wp_".$blog."_options";
      $blogPostsTable = "wp_".$blog."_posts";
      $opt = $wpdb->get_col("SELECT option_value FROM $blogOptionsTable WHERE option_name='siteurl'");
      $opt2 = $wpdb->get_col("SELECT option_value FROM $blogOptionsTable WHERE option_name='blogname'");
      // we fetch the title for the latest post
      $opt3 = $wpdb->get_col("SELECT post_title FROM $blogPostsTable WHERE post_status = 'publish' ORDER BY id DESC LIMIT 0,1");
      // we fetch the link for the latest post
      $opt4 = $wpdb->get_col("SELECT guid FROM $blogPostsTable WHERE post_status = 'publish' ORDER BY id DESC LIMIT 0,1");
      print "<li class=\"page_item\"><h4>".ucfirst($opt2[0])."</h4>$opt3[0]";
      endforeach;
      ?>

    </div>

  5. andrea_r
    Moderator
    Posted 16 years ago #

    Yep, that's what we started with, only now it's streamlined a bit.

    Other than that, I'd have to check line-by -line and I'm not caffeinated yet. ;)

  6. ergate
    Member
    Posted 16 years ago #

    This is the same code that I modified, and is on my front page. Way back in january I posted this code on my mu site, to this link. http://info.cultureofcomplaint.com/2006/01/08/code-for-most-recently-updated-blog/

    By this point in time I am also using Fimi's plugin, and widgetizing themes (to take advantage of the rss function, display one blog on my home page as a news blog).

  7. samchng
    Member
    Posted 16 years ago #

    Thanks andrea. :)

    ergate: "display one blog on my home page as a news blog"
    You mean you are displaying the admin blog on your home.php? I am currently using home.php as a main page and admin blog is on index.php (a so called news page).

    By saying Fimi's plugin, which one you are referring to?

    Regarding wigetizing themes, I think you can help out andrew on another thread. ;)

  8. amnesiak
    Member
    Posted 16 years ago #

    I think thats from my http://www.iktib.com (@sam)

    @others, people said that the code is streamlined but what are the actual changes?

    Would I need to delete andrew's plugin and install a new plugin?

    regards,
    Kei

  9. andrewbillits
    Member
    Posted 16 years ago #

    Nah, my plugin just adds a function you can call from anywhere. It can peacefully coexist with pretty much any other plugin.

  10. ergate
    Member
    Posted 16 years ago #

    samchng: what I ment by "display one blog on my home page as a news blog", I went and added the Widgets plugin to my site and the widget functions to my Main theme, I am now using the rss feed widget to display the entries from one blog as a news blog.
    Ideally I think I would like to use a script, such as the ones talked about in this thread, but using a single rss widget was so easy, it will work for the mean time.

  11. samchng
    Member
    Posted 16 years ago #

    ergate: Thanks for the explaination, will try to work at what you are doing. Get back to ya if I have any probs. :)

    Kei: Nope the code is from a zip file. Any how it doesn't matter. Haha.

  12. andrea_r
    Moderator
    Posted 16 years ago #

    ergate, mind if we plugin-ify this? I'll give credit of course.
    (worked on it today, update to follow with notes on changes)

  13. samchng
    Member
    Posted 16 years ago #

    Yeah andrea! Good suggestions! I would volunteer to give it a test run. Still learning php. :)

  14. ergate
    Member
    Posted 16 years ago #

    andrea_r: plug away.
    Originally this was not mine, I dont remember who it was I got it from, I think the post is lost in the forum restart ether.
    It is actually pretty easy to modify, just start swapping in-out different table/column names and you can have a lot of different variations.

  15. andrea_r
    Moderator
    Posted 16 years ago #

    Bumping because new people have asked about this in other threads. :) We're still working on it too.

    Oh, and I did do one quick-and-dirty mod to it to find out which users were using what themes. Now THAT was handy when I had to go over every user and upgrade them to a Widgetized theme. (because they had been using the Sidebar Editor plugin and I didn't want to blow away their custom info)

  16. mirsasha
    Member
    Posted 16 years ago #

    It looks like this is just showing a post title and link, is that correct? Also, it's excluding posts to the main blog, right? Thanks!

  17. andrea_r
    Moderator
    Posted 16 years ago #

    Yep. :)

  18. nuprn1
    Member
    Posted 16 years ago #

    I posted this in another thread, but this is what i'm using on my MU install. I took the above code and modified it so it will truly pull out the last updated with the content of those posts. It will pull out the 5 recent from each blog and sort them.

    I'm sure it could be re-written but it works for now


    <div class="recentpostings">
    <h2><?php _e('Recent Postings on DUBBlogs'); ?></h2>

    <?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 = "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 guid != '' ORDER BY id DESC LIMIT 0,5");
    //push into array, had $postresults[] = $postitems;, but didn't work?

    if ($postitems) {
    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 cutpost($text) { // Fakes an excerpt if needed

    $text = apply_filters('the_content', $text);
    $text = str_replace(']]>', ']]>', $text);
    $text = strip_tags($text);
    $excerpt_length = 55;
    $words = explode(' ', $text, $excerpt_length + 1);
    if (count($words) > $excerpt_length) {
    array_pop($words);
    array_push($words, '[...]');
    $text = implode(' ', $words);
    }
    return $text;
    }
    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');
    $postresults = array_slice($postresults, 0,25); //limit number of results

    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'");

    //todo - this is an array, need to sort and pull out
    //$catitems = $wpdb->get_col("SELECT category_id FROM wp_".$postresult[6]."_post2cat WHERE $postitems->ID ORDER BY category_id");

    ?>
    <div id="post-" class="item entry">
    <div class="itemhead">
    <h3><a href="<?php echo $postresult[2]; ?>" rel="bookmark" title='Permanent Link to "<?php echo $postresult[1]; ?>"'><?php echo $postresult[1]; ?></a></h3>
    </div>
    <div class="itemtext">
    <?php echo cutpost($postresult[3]);?>
    </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 } ?>
    </div>

  19. mirsasha
    Member
    Posted 16 years ago #

    This looks like it's more what I was looking for. I'll give it a try. Thanks for posting!

  20. CoreyCampbell
    Member
    Posted 15 years ago #

    Is there anyway to make it so you can view how many comments a post has?

      <?php
          $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE domain!='site.com' AND last_updated!='0000-00-00 00:00:00' ORDER BY last_updated DESC LIMIT 10");
          foreach ($blogs as $blog) :
          // we need _posts and _options tables for this to work
          $blogOptionsTable = "wp_".$blog."_options";
          $blogPostsTable = "wp_".$blog."_posts";
          $opt = $wpdb->get_col("SELECT option_value FROM $blogOptionsTable WHERE option_name='siteurl'");
          $opt2 = $wpdb->get_col("SELECT option_value FROM $blogOptionsTable WHERE option_name='blogname'");
          // we fetch the title for the latest post
          $opt3 = $wpdb->get_col("SELECT post_title FROM $blogPostsTable WHERE post_status = 'publish' ORDER BY id DESC LIMIT 0,1");
          // we fetch the link for the latest post
          $opt4 = $wpdb->get_col("SELECT guid FROM $blogPostsTable WHERE post_status = 'publish' ORDER BY id DESC LIMIT 0,1");
          print "<li class="updated-blogs"><a href="$opt4[0]"><span class="updated-blogname">".ucfirst($opt2[0]).":</span> $opt3[0]</a></li>";
          endforeach;
          ?> 
  21. af3
    Member
    Posted 14 years ago #


  22. pardisi
    Member
    Posted 13 years ago #

    but this function it return the link of post "guid"...
    what about permanent link???
    thanks

About this Topic

  • Started 16 years ago by andrea_r
  • Latest reply from pardisi