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:
In drupal 7, this snippet should be modified since there is no pager_query anymore. The modified version I now have is
- (2013 02 15) Predicting a supernova precursor (on SN2010mc)
- (2013 01 02) Dust Dendrites
- (2011 09 28) Why don't I believe the that neutrinos travel faster than the speed of light?
- (2010 12 31) From Masada to the Messinian Salinity Crisis
- (2010 02 03) A visit to Stromboli
- (2008 01 11) Bush in a quantum entangled state
- (2007 12 29) Corpuscular Rays in St. Peter's Basilica (the Vatican)
- (2007 12 13) A Nice Black Hole Merger Simulation
- (2007 04 22) Parhelic Circles, Ice Haloes and Sun dogs over Jerusalem
- (2006 05 26) Have you heard of the silent Earthquake?
- $listlength="300";
- $taxo_id = "12";
- $content_type = 'blog';
- $result = pager_query("SELECT n.title, n.nid, n.uid, n.created, u.name FROM {node} n
- INNER JOIN {users} u ON n.uid = u.uid INNER JOIN term_node ON n.nid = term_node.nid
- WHERE n.type = '$content_type' AND term_node.tid in ($taxo_id) AND n.status = 1
- ORDER BY n.created DESC", $listlength);
- $output = "<ol>";
- while ($node = db_fetch_object($result)) {
- $output .= "<li><small>" .format_date($node->created,'custom','(Y m d)',
- $timezone = NULL)." </small> ".l($node->title, "node/$node->nid") ."</li>";
- }
- $output .= "</ol >";
- 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)." </small> ".l($node->title, "node/$node->nid") ."</li>";
}
$output .= "</ol >";
print $output;
$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)." </small> ".l($node->title, "node/$node->nid") ."</li>";
}
$output .= "</ol >";
print $output;