Show block if inside specific book

If you wish to display a block only while showing a page from a specific book, try the following:

  1. Go to the block you want to edit and click configure
  2. Go to the "Page specific visibility settings"
  3. Choose the option: "Show if the following PHP code returns TRUE"
  4. Paste in the code below
  5. Change the two values of 46 to the node ID of the book you're testing against

Then the block should only display if you're inside that particular book.

<?php
if (arg(0) == "node" && is_numeric(arg(1))) {
  if (
46 == arg(1)) {
    return
TRUE;
  }
 
$result = db_fetch_object(db_query("SELECT parent FROM {book} WHERE nid = %d", arg(1)));
  if (
46 == $result->parent) {
    return
TRUE;
  } else {
    return
FALSE;
  }
} else {
  return
FALSE;
}
?>

This snippet is from help provided in this forum thread: http://drupal.org/node/125344. Thanks to all who helped!

 
 

Drupal is a registered trademark of Dries Buytaert.