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:
- Go to the block you want to edit and click configure
- Go to the "Page specific visibility settings"
- Choose the option: "Show if the following PHP code returns TRUE"
- Paste in the code below
- 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!
