The MU forums have moved to WordPress.org

php code for most recently updated blog (42 posts)

  1. Farms
    Member
    Posted 18 years ago #

    Depsperate and clueless php newbie here... I have found the code for displaying latest updated blogs in wpmu-functions.php but I don't know how to get this code function on the homepage...

    Could anyone share their code with me... would b every much appreciated!

    james /at/ edublogs (dot) org

    Enooooooooormously appreciated!

    James

  2. Farms
    Member
    Posted 18 years ago #

    OK, here's where I'm at...

    I don't want to pull in the list of most postd any more (which is just as well as the copied script I was using doesn't work anymore :o) so I'm trying to get 'how many edublogs' and 'most recently updated' going but with litrtle success...

    This works fine for getting the number:

    <?php

    switch( $_GET[ 'action' ] ) {
    default:
    // print some global stats.
    $stats = get_sitestats();
    print "<h3>Who's on at edublogs?</h3><br><br>
    There are currently ".$stats[ 'blogs' ]." edublogs, here are the most active:</p><br /><br />
    ";

    }

    ?>

    But this one does *not* pull up the latest updated blogs:

    `<?php

    switch( $_GET[ 'action' ] ) {
    default:
    // gets last updated
    $blogs = get_last_updated();
    print "<h3>Latest updated</h3><br><br>
    ".$blogs."
    ";

    }

    ?>'

    Could anyone tell me why, make some suggestions as to what I could do?

    Your time much appreciated!

    Cheers, James

  3. Farms
    Member
    Posted 18 years ago #

    Am currently using this as a testbed...a s you can see it also creates some errors (am using teh 9 Aug unstable for this): http://londonblogs.org/

  4. Farms
    Member
    Posted 18 years ago #

    If I composed a small ditty would that help...

    Ode to WPMU Forum code assistance

    If it were that I could
    set up php as I should
    then I would not have to plea
    or ask for this little wee
    bit of help to code my index
    that has left me perplex'
    then you would not have to hear
    me rattling on in your ear
    and everything would be just fine
    until I fuck it up again, next time.

    Thankyou.

  5. donncha
    Key Master
    Posted 18 years ago #

    It's very good :) I've been busy all morning with invites, but I'm going to do some work on a front page and those functions after I have some lunch... That's the problem doing something you enjoy, forget to eat sometimes.

  6. Farms
    Member
    Posted 18 years ago #

    I know *exactly* what you mean!

    Have managed to corner someone who actually knows what they're doing with php (um, well, more than me) this afternoon.

    Are there any chunks of code I could take along or are they encoded directly into WPMU?

    Cheers, James

  7. Farms
    Member
    Posted 18 years ago #

    Phew... I *almost* understand :)

    I think I'm doing the right thing when I ask it to call these:

    <?php

    $stats = get_sitestats();
    print "<h3>Who's on at edublogs?</h3><br><br>
    There are currently ".$stats[ 'blogs' ]." edublogs, here are the latest updated:</p><br /><br />
    ";

    $blogs = get_last_updated();
    print "".$blogs."
    ";

    ?>

    But I still get the error:

    "

    WordPress database error: [Table 'lndblogs_wpmu.wp__options' doesn't exist]
    SELECT option_value FROM wp__options WHERE option_name = 'is_archived'

    WordPress database error: [Table 'lndblogs_wpmu.wp__options' doesn't exist]
    SELECT option_value FROM wp__options WHERE option_name = 'is_archived'

    WordPress database error: [Table 'lndblogs_wpmu.wp__options' doesn't exist]
    SELECT option_value FROM wp__options WHERE option_name = 'is_archived'
    Array"

    (see it here: http://londonblogs.org)

    So... is it an error in the database? How to fix?

    Thanks for your time!

    James

  8. inertia
    Member
    Posted 18 years ago #

    I need that too :) I'm pumping up the thread.

  9. jaseone
    Inactive
    Posted 18 years ago #

    This is what I am using via modifying Wugga's code:

    <?php
    print "<h2>911 Blogs Stats</h2>";
    $stats = get_sitestats();
    print "<li><ul><li>".$stats[ 'blogs' ]." blogs and ".$stats[ 'users' ]." users</li></ul></li>";
    ;
    $blogs = get_blog_list();
    $most_active = get_most_active_blogs( 10, false );
    if( is_array( $most_active ) ) {
    print "<h2>Most Active</h2>";
    print "<li><ul>";
    while( list( $key, $details ) = each( $most_active ) ) {
    $class = ('alternate' == $class) ? '' : 'alternate';
    $url = "http://" . $details[ 'domain' ] . $details[ 'path' ];
    print "<li><a href=\"".$url. "\">".$url."</a></li>";
    //$details['postcount']
    }
    print "</ul></li>";
    }
    ?>

  10. comforteaglespaceman
    Inactive
    Posted 18 years ago #

    jaseone: where are you placing that code? I keep using an include, but can't get it to align nicely.

  11. jaseone
    Inactive
    Posted 18 years ago #

    That is just in my sidebar.php

  12. comforteaglespaceman
    Inactive
    Posted 18 years ago #

    whoops, sorry, I knew that's where it would go, but where do put the include for the sideline.php file?

  13. inertia
    Member
    Posted 18 years ago #

    Hey thank!

  14. plainsman
    Member
    Posted 18 years ago #

    donncha, or anyone else, using that code to display active blogs ... is there a way to include something like exclude="blog_id" or some other method in order to 'not' display certain blogs in that list?

    I tried the exlude function one may use in WordPress 1.5 in listing your links, etc... but can't get it to work in this code on a WPMU blog.

    Has anyone accomplished this, or knows of a way to accomplish it?

    Thank you.

  15. mspecht
    Member
    Posted 18 years ago #

    You would have to change get_most_active_blogs to have a 3rd parameter exclude=Z,X,Y and then pass it through to get_blog_list and exlcude within this function. Not sure what other damage it would do. The function is removing archived blogs so you could just archive the ones you don't want to appear.

  16. J2000_ca
    Inactive
    Posted 18 years ago #


    <?php $stats = get_sitestats();?>
    <h1 class="tooltitle">Uloo Hosted Blogs (<?php print $stats[ 'blogs' ];?>)</h1>
    <ul id="Blogs">
    <?php
    $blogs = get_blog_list();
    $most_active = get_most_active_blogs(10, false);
    foreach($most_active as $blog)
    print "
    <li><a>".$blog[ 'domain' ]."</a></li>
    ";?>

  17. mirsasha
    Member
    Posted 18 years ago #

    Is there a way to have, say, the top 10 most recent posts show on the main blog/domain's home page? Essentially, turning that page into an aggregator for the whole community?

  18. jasongolod
    Inactive
    Posted 18 years ago #

    Gang I am using this:

    <h2>Most Active Members</h2>

      <?php get_most_active_blogs(); ?>

    Still working on getting the most recent posts for the whole community going.

  19. Farms
    Member
    Posted 18 years ago #

    Oh... to get that working... a bevy of virtual beer to whoever can sort that out!

  20. wugga
    Member
    Posted 18 years ago #

    Do you mean like I have on the front page of http://wugga.com ?

    Can you get a bevy of non-virtual beer to Colorado ;-)

    Exactly how much is a bevy?

  21. Farms
    Member
    Posted 18 years ago #

    Yes, exactly!

    Now a bevy of virtual beer is, realisitically however much you want it to be - being virtual it doesn't really matter ;)

    But lots of lovely karma and grateful linkages from my 3 x PR6 sites could be a bit more tangible?

    Cheers, James

  22. Farms
    Member
    Posted 18 years ago #

    Big cheer for Michele of the rather beautiful http://beblogger.com who donated this code, pulls up latest updated blogs from the MySQL without a hitch!

    <h2>Last Updated</h2>
    <div class="comments">
    <ul>
    <?
    $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE domain!='beblogger.com' AND last_updated!='0000-00-00 00:00:00' ORDER BY last_updated DESC LIMIT 10");
    foreach ($blogs as $blog) :
    $blog = "wp_".$blog."_options";
    $opt = $wpdb->get_col("SELECT option_value FROM $blog WHERE option_name='siteurl'");
    $opt2 = $wpdb->get_col("SELECT option_value FROM $blog WHERE option_name='blogname'");
    print "<li><a href='$opt[0]'title='$opt2[0]'>".ucfirst($opt2[0])."</a>n";
    endforeach;
    ?>
    </ul>
    </div>

  23. Farms
    Member
    Posted 18 years ago #

    see it in action on the sidebar of the 'all new' http://edublogs.org

  24. Inviz
    Inactive
    Posted 18 years ago #

    i wrote whole table with full stats of blogs. here is url http://mu.wordpress.org/forums/topic/478

  25. michelem
    Member
    Posted 18 years ago #

    Hi guys and thanks Farms for the reference, you are welcome.
    I would like to give you another little piece of code to list every blog's users link.
    I used it in a wp page, you only need to create a page like "Blogs" and in the page.php create an if condition like:

    <? if (is_page('blogs')) : ?>
    <h2 id="post-<?php the_ID(); ?>">" rel="bookmark"><?php the_title(); ?></h2>

      <?
      // this function is in wp-includes/wpmu-functions.php
      // get the array of blogs
      $blogs = get_blog_list(0, 'all');
      foreach ($blogs as $blog) :
      // This is the table to get the blogname
      $tblog = "wp_".$blog['blog_id']."_options";
      $blogname = $wpdb->get_col("SELECT option_value FROM $tblog WHERE option_name='blogname'");
      // print one line each blog with: blogurl - blogname [num posts]
      print "

    • http://".$blog['domain']." - ".ucfirst($blogname[0])." <small>[".$blog['postcount']." posts]</small>\n";
      endforeach;
      ?>

    // etc...
    <? else: ?>
    // etc...
    <? endif; ?>

    That's all folks :) You can see it in action: http://beblogger.com/blogs/

    The source code here is better: http://www.rafb.net/paste/results/J61Bez65.html

  26. theworkisdone
    Member
    Posted 18 years ago #

    Three lines of (not optimized) code added to michele's very much appreciated code to display the latest post in the latest updated blog:

    ---8<--------snip---8<------
    $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;
    ---8<--------snip---8<------

  27. theworkisdone
    Member
    Posted 18 years ago #

    Whoops the print-line got filtered by this forum

    print "<li class=\"page_item\"><h4>".ucfirst($opt2[0])."</h4>$opt3[0]";

  28. theworkisdone
    Member
    Posted 18 years ago #

    Again, sorry :-/

    please use $opt[0],$opt2[0],$opt3[0],$opt4[0] an build the list and links for yourself...

  29. wugga
    Member
    Posted 18 years ago #

    Proof that there's more than one way to skin a cat. I hacked together a version as well but then found out that it was a builtin function. Just call get_last_updated(). There is a bug in my version of the function where a comma is missing after blog_id in the second line of the function. Once you have the array you can loop through it and grab titles or query the individual blogs and get the last posts.
    I think using the function is the best and cleanest route but I'm still looking over the above code. The builtin function grabs 40 rows by default but that can be edited to return whatever you want.

    You can see it in action on the front page of http://wugga.com

  30. mydietblogger
    Inactive
    Posted 18 years ago #

    Hey,

    I tried implementing Michelle's code, but I am bombarded with Mysql Errors. any idea?

    check it out at http://www.mydietblogger.com

    Help would be greatly appreciated :)

About this Topic