Diplay a list of nodes not part of a book

Note from the moderator: Thank you for sharing the snippet with the Drupal community. In its current state the snippet might present security risks. See Writing secure code for a background on the most common mistakes.

Specifically, the snippet

The bypass may be the intention; Perhaps it is only meant for administrators? An alternative is to check user_access('administer nodes') upon entry of the snippet to ensure only those with the proper permission view the nodes.

I wanted to see what content would be potentially useful as part of a book, but was just sitting there as an unattached node, i.e. not a child page of any other. I wasn't interested in images or project issues as potential book content. You might like to exclude other types.
Leave the n.type <> "book" . That indicates a node that is the root page of a book so it is supposed to be unattached.

Note: admin/node/book/orphan looks only at type 'book page', whereas this snippet looks at type 'page' and 'project' and ... and asks the question whether they should become a book page.
Orphans are about nodes that were once a part of a book and got cut off. This snippet is about loose content that maybe should be bound up in a book.

Create a new page, copy this code to the body, select input format "PHP code" and submit.

Not necessarily a bad thing.  They just may be candidates for adding to an online book.

We exclude book and image and project_issue.
Group by type, then most recent first

<?php
$sql
= 'SELECT n.nid, n.title, n.type
FROM node n
          LEFT JOIN book b ON n.nid=b.nid
          WHERE b.nid IS NULL
          and n.type <> "book" and n.type <> "image"
              and n.type <> "project_issue"
          ORDER BY n.type, n.created DESC'
;
$result = db_query($sql);
while (
$anode = db_fetch_object($result)) {
   
   
$items[]= array(l($anode->nid,'node/'.$anode->nid) ,
                   
$anode->title,
                   
$anode->type,
                   
l('edit','node/'.$anode->nid.'/edit')
              );
}  
print
theme('table', array('Node','Title', 'Type',''), $items);

?>

 
 

Drupal is a registered trademark of Dries Buytaert.