Community Documentation

List of nodes in 5.x

Last updated May 21, 2007. Created by palik on May 2, 2007.
Log in to edit this page.

Just one line changed from 4.7 version of the script, as node_get_name function no longer exists in 5.x. Enjoy!

update - how to use this? just create new block, insert code, set format to php, set block to be visible on "user/*" pages, and you are done.

<?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_types("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);
  }
?>

About this page

Drupal version
Drupal 5.x
Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.