php code to get the 10 latest nodes published ?

poseidon123 - July 20, 2008 - 15:17

I know views can easily do it but I want the php code to get the 10 latest nodes published of the content type "page" ? :)

Try this

archard - July 20, 2008 - 18:00

<?php
$sql
= "SELECT * FROM {node} WHERE type = 'page' AND status = 1 ORDER BY created DESC LIMIT 10";
$result = db_query(db_rewrite_sql($sql));
$latest_nodes = array();
while (
$data = db_fetch_object($result)) {
 
$latest_nodes[] = l($data->title, 'node/' . $data->nid);
}

print
theme('item_list', $latest_nodes);
?>

warning:

poseidon123 - July 20, 2008 - 18:26

warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/mysite/html/includes/database.mysql.inc on line 188.

I am getting this error :(

It works for me. Are you

archard - July 20, 2008 - 20:52

It works for me. Are you using Drupal 5 or 6?

5.7

poseidon123 - July 21, 2008 - 17:00

5.7

 
 

Drupal is a registered trademark of Dries Buytaert.