Making a block with an expanded book menu for Drupal 6

So, what can I say, I really don't like that the book module doesn't have an option to set it's menu to be expanded by default. Perhaps, I could make a patch, or make a contrib module to allow for such. There is a page on how to do this on however it contains a whole lot of unneeded code as well as confusing instructions. Meanwhile, see below for the code you can use in a custom module to create a block with an automatically expanded book menu. 

If you do not know how to create a custom module, please see my blog post how to easily create a custom module in Drupal 6. Just put this in your .module file once you have created it and then enable the module and then enable the block and put it where you want it to go. You can change <none> to be the menu title if you want one. Change the number 1 to be the number of your book's id. If you only have one book then just leave it at 1.




 * Implementation of hook_block().

 * Adds a block with expanded book navigation


function book_expand_block($op = 'list', $delta = 0, $edit = array()) {

  switch ($op) {

    case 'list':

      $blocks[0]['info'] = t('Book menu expanded');

      return $blocks;

    case 'view':

      $block[0]['subject']['title'] = '<none>';

      $book_data = menu_tree_all_data(book_menu_name(1));

      $block[0]['content'] = menu_tree_output($book_data);

      return $block[$delta];




Comment using an existing account (Google, Twitter, etc.)