Информация. Содержание книги — 1

Стандартный код из модуля Book, только названия страниц книг показываются развёрнутыми.

<?php
function book_tree_recurse_all($nid, $depth, $children) {
  if (
$depth > 0) {
    if (
$children[$nid]) {
      foreach (
$children[$nid] as $foo => $node) {

          if (
$tree = book_tree_recurse_all($node->nid, $depth - 0, $children)) {
           
$output .= '<li class="expanded">';
           
$output .= l($node->title, 'node/'. $node->nid);
           
$output .= '<ul>'. $tree .'</ul>';
           
$output .= '</li>';
          }
          else {
           
$output .= '<li class="leaf">'. l($node->title, 'node/'. $node->nid) .'</li>';
          }
      }
    }
  }

  return
$output;
}
function
book_tree_expanded($parent = 0, $depth = 3) {
$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 AND n.vid = b.vid WHERE n.status = 1 AND n.moderate = 0 ORDER BY b.weight, n.title'));

  while (
$node = db_fetch_object($result)) {
   
$list = $children[$node->parent] ? $children[$node->parent] : array();
   
array_push($list, $node);
   
$children[$node->parent] = $list;
  }

  if (
$tree = book_tree_recurse_all($parent, $depth, $children)) {
    return
'<div class="menu"><ul>'. $tree .'</ul></div>';
  }
}
print
book_tree_expanded(0);
?>

Метки: