Integration with Nice Menus module

Last modified: April 7, 2007 - 21:46

this is a variant of the above code, which displays the book contents using nice_menus.module:

<?php
$book_top_page
= 159;
$book_top_title = "menu name";
$levels_deep = 2;
$nice_direction = "right";
$emulate_book_block = true;

if (!
function_exists('book_struct_recurse')){
  function
book_struct_recurse($nid, $levels_deep, $children, $current_lineage = array(), $emulate_book_block = true) {
   
$struct = '';
    if (
$children[$nid] && ($levels_deep > 0 || ($emulate_book_block && in_array($nid, $current_lineage)))) {
     
$struct = '<ul>';
      foreach (
$children[$nid] as $key => $node) {
        if (
$tree = book_struct_recurse($node->nid, $levels_deep - 1, $children, $current_lineage, $emulate_book_block)) {
         
$struct .= '<li class="menuparent">';
         
$struct .= l($node->title, 'node/'. $node->nid);
         
$struct .= $tree;
         
$struct .= '</li>';
        }
        else {
          if (
$children[$node->nid]){
           
$struct .= '<li class="collapsed">'. l($node->title, 'node/'. $node->nid) .'</li>';
          }
          else {
           
$struct .= '<li class="leaf">'. l($node->title, 'node/'. $node->nid) .'</li>';
          }
        }
      }
     
$struct .= '</ul>';
      return
$struct;
    }
  }
}

$current_lineage = array();

$result = db_query(db_rewrite_sql('SELECT n.nid, n.title, b.parent, b.weight FROM {node} n INNER JOIN {book} b ON n.nid = b.nid WHERE n.status = 1 ORDER BY b.weight, n.title'));

while (
$node = db_fetch_object($result)) {
  if (!
$children[$node->parent]) {
   
$children[$node->parent] = array();
  }
 
array_push($children[$node->parent], $node);
 
  if (
arg(0) == 'node' && is_numeric(arg(1)) && arg(1) == $node->nid) {
   
$_temp = book_location($node);
    foreach (
$_temp as $key => $val){
     
$current_lineage[] = $val->nid;
    }
   
$current_lineage[] = arg(1);
  }
}

echo
"<ul class='nice-menu nice-menu-$nice_direction'>".
   
"<li class='menuparent'>".l($book_top_title, 'node/'.$book_top_page).
   
book_struct_recurse($book_top_page, $levels_deep, $children, $current_lineage, $emulate_book_block);
   
"</li></ul>";
?>

Book navigation with nice menus for D6

koorneef - September 22, 2008 - 19:36

See: http://drupal.org/node/236418#comment-1024401

The code above won't work for D6.

 
 

Drupal is a registered trademark of Dries Buytaert.