cloudsoup

no soup, no clouds

First WordPress Hack

leave a comment

This weblog was moved from MoveableType to WordPress just a few days ago and we’ve already created our first hack.

The hack sits in the my-hacks.php file and implements a function to return a list of the {n} most recently posted items. Here it is:


function get_recent_posts($limit = 10) {
   global  $wpdb, $tableposts;
   $list = \"<ul>n\";
   $rows = $wpdb->get_results(\"
         SELECT ID, post_title, post_date,
         post_name FROM $tableposts
         WHERE post_status = 'publish'
         ORDER BY post_date DESC
         LIMIT 1, \".$limit);
   foreach($rows as $row){
      $list .= \"<li><a href=\"\".get_permalink($row->ID) .
            \"\">\" . $row->post_title . \"</a></li>n\";
   }
   $list .= \"</ul>n\";
   echo($list);
}

Feel free to use it yourselves.

Written by David

May 16th, 2004 at 5:28 pm

Posted in Uncategorized

Tagged with ,

Leave a Reply