Community & Support

php code to get the 10 latest nodes published ?

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" ? :)

Comments

Try this

<?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:

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

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

5.7

5.7

nobody click here