List nodes in 4.7
Last modified: February 10, 2009 - 14:20
This is a rewite of the snippet with some code improvements that works in 4.7.
To add other columns to the table, you should edit the $headers array and the $rows[] line.
<?php
$nblimit = 50; // max nodes to show, edit this value
// Get the user id
$uid = arg(1);
if (is_numeric($uid)) {
// SQL query to retrieve the nodes created by the user
$query = "
SELECT created,
title,
nid,
changed,
status,
type
FROM {node}
WHERE uid ='". db_escape_string($uid) ."'
AND status=1
ORDER BY changed DESC
";
// Execute the query while limiting the number of results
$result = db_query_range($query, 0, $nblimit);
// Defines the 3 columns of our table
$headers = array(
t('Type'),
t('Title'),
t('Action')
);
// Initializes the rows
$rows = array();
// Loop over each found nodes
while ($node = db_fetch_object($result)) {
// Add a row to our table
$rows[] = array(
t(node_get_name($node->type)),
l($node->title, 'node/'. $node->nid),
l(t('edit'), 'node/'. $node->nid .'/edit')
);
}
// Ask Drupal to theme our table
return theme('table', $headers, $rows);
}
?>