I have a 3 level deep book navigation block. I'd like to change the menu tree HTML output in the following way: For each level of the tree, create a li and inside it put an anchor tag with the active-trail link for that level, and afterwards a ul with the rest of the siblings for that level.

    <a href="#" class="active-trail level[x]">Level[x] active trail link</a>
    <ul style="display:none;">
        <li><a href="#">Level[x] sibling1</a></li>
        <li><a href="#">Level[x] sibling2</a></li>
        <li><a href="#">Level[x] sibling3</a></li>
        <li><a href="#">Level[x] sibling4</a></li>        

The order of sibling links appearance should be according to their corresponding node weight.

I thought this could be done via the theme_menu_link() function but I can't seem to find a way to pass the current item's depth to the function.

What function do I have to work with in order to achieve what I'm after? Can someone offer some guidance?

Thanks, Avner

1 Answer 1


There is a specific theme function, which is used from the Book module for outputting its own block of links to book pages. I am not sure if it suits your case, but you can always use that code to build your own theme function.

The theme function is called from book_block(), using the following code:

  if (variable_get('book_block_mode', 'all pages') == 'all pages') {
    $block['subject'] = t('Book navigation');
    $book_menus = array();
    $pseudo_tree = array(0 => array('below' => FALSE));
    foreach (book_get_books() as $book_id => $book) {
      if ($book['bid'] == $current_bid) {
        // If the current page is a node associated with a book, the menu
        // needs to be retrieved.
        $book_menus[$book_id] = menu_tree_output(menu_tree_all_data($node->book['menu_name'], $node->book));
      else {
        // Since we know we will only display a link to the top node, there
        // is no reason to run an additional menu tree query for each book.
        $book['in_active_trail'] = FALSE;
        $pseudo_tree[0]['link'] = $book;
        $book_menus[$book_id] = menu_tree_output($pseudo_tree);
    $block['content'] = theme('book_all_books_block', $book_menus);

The theme_book_all_books_block() function is empty, because the theme is using a template (book-all-books-block.tpl.php); as far as I can see, there isn't a preprocess function for that template file.

  • Thank you. Took your advice, and used the code you've provided here to build my own theme function. The main idea was to get a flat, one-level array of the book navigation hierarchy, and then split this one array into multiple arrays based on the elements depth. I used this function: book_get_flat_menu($node->book); Probably not the nicest code, but managed to get it to work exactly as needed. Aug 23, 2011 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.