Drupal 6: get parent nid of a book child page

Submitted by fabio on Fri, 2008-06-27 18:07.

I had to get the parent nid of a book child page for a website which already uses Drupal 6.

Seems that the book module logic has changed deeply between version 5. The new stack implementation of the parent-child relationships is pretty complex, at least for me. I have to say that I did not studied it a lot thought.

So.. this is the code to do that:

<?php

if(isset($node->book)) { // book page
      $parent = book_link_load($node->book['plid']);
      $pid = $parent['nid'];
}

?>

Hope this helps.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <pre> <img> <h2> <h3> <h4> <b>
  • Lines and paragraphs break automatically.
  • Images can be added to this post.
  • You may use [inline:xx] tags to display uploaded files or images inline.

More information about formatting options

3 + 0 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.