The MU forums have moved to WordPress.org

Updated Blogs Widget (3 posts)

  1. CoreyCampbell
    Member
    Posted 15 years ago #

    How can I make the following code a widget for mu?

    		<ul>
          <?php
          $blogs = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs WHERE domain!='mkcproductions.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;
          ?>
    		</ul>

    I'm a bit of noob at the widgets, so lot's of help might be required.

  2. mysorehead
    Member
    Posted 15 years ago #

    Copy and rename the gsearch.php file in the widgets folder (or wherever it is for you) to something that describes your new widget. This file is well documented (if use use an editor that colour codes the comments it will easier to read). Follow the hints.

    You could also do a couple of find and replaces - replacing gsearch with your chosen function name (something without spaces) and Google Search with your widget title. Then cut out the google search specific code and add your code into the same place. This may help get you into it.

    Maybe turn on errors as well - that helps debugging.

    error_reporting(E_ALL);

    Hope this helps, I'm happy to answer questions but you'll learn more by nutting it out yourself,

    Richard

  3. CoreyCampbell
    Member
    Posted 15 years ago #

    Yeah thanks. I love doing that. But I know that I'm going to get something wrong. I'll continue to post the code. Thanks mysorehead!

About this Topic

  • Started 15 years ago by CoreyCampbell
  • Latest reply from CoreyCampbell