Upgrading drupal 5 or 6 snippets to drupal 7

After I upgraded from drupal 5 to drupal 6 and then to drupal 7, I realized that some of my php snippets stopped working. So, I looked around and found a few links discussing it. As an example of a modification I had to do, here is snippet that prints out a list of nodes by content type (in this case 'blog') and by taxonomy id (in this case 12). It provides a list like this one:
  1. (2013 02 15)  Predicting a supernova precursor (on SN2010mc)
  2. (2013 01 02)  Dust Dendrites
  3. (2011 09 28)  Why don't I believe the that neutrinos travel faster than the speed of light?
  4. (2010 12 31)  From Masada to the Messinian Salinity Crisis
  5. (2010 02 03)  A visit to Stromboli
  6. (2008 01 11)  Bush in a quantum entangled state
  7. (2007 12 29)  Corpuscular Rays in St. Peter's Basilica (the Vatican)
  8. (2007 12 13)  A Nice Black Hole Merger Simulation
  9. (2007 04 22)  Parhelic Circles, Ice Haloes and Sun dogs over Jerusalem
  10. (2006 05 26)  Have you heard of the silent Earthquake?
The a drupal 5 (or drupal 6) version of the code looks like this:
  1.    $listlength="300";
  2.    $taxo_id = "12";
  3.    $content_type = 'blog';
  4.    $result = pager_query("SELECT n.title, n.nid, n.uid, n.created, u.name FROM {node} n
  5. INNER JOIN {users} u ON n.uid = u.uid INNER JOIN term_node ON n.nid = term_node.nid
  6. WHERE n.type = '$content_type' AND term_node.tid in ($taxo_id) AND n.status = 1
  7. ORDER BY n.created DESC", $listlength);
  8.    unset ($output);
  9.    $output = "<ol>";
  10.    while ($node = db_fetch_object($result)) {
  11.         $output .= "<li><small>" .format_date($node->created,'custom','(Y m d)',
  12. $timezone = NULL)."&nbsp;</small> ".l($node->title, "node/$node->nid") ."</li>";
  13.    }
  14.    $output .= "</ol >";
  15.    print $output;


In drupal 7, this snippet should be modified since there is no pager_query anymore. The modified version I now have is
    $taxo_id = 12;
    $content_type = 'blog';
    $status = 1;  /* 1=published */
    $result = db_query("SELECT n.title, n.nid, n.uid, n.created  FROM {node} n INNER JOIN
{taxonomy_index} tn ON n.nid = tn.nid WHERE n.type = :type AND tn.tid in ( :term ) AND
n.status= :status ORDER BY n.created DESC"
, array(
    ':type' => 'blog',
    ':status' => $status,
    ':term' => $taxo_id,
    ));
    unset ($output);
    $output = "<ol>";
    foreach ($result as $node) {
        $output .= "<li><small>" .format_date($node->created,'custom','(Y m d)',
$timezone = NULL)."&nbsp;</small> ".l($node->title, "node/$node->nid") ."</li>";
    }
    $output .= "</ol >";
    print $output;

Share