BookTree二级显示

第一种:

<?php
$result = db_query('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = 0 ORDER BY b.weight ASC');

while( $n = db_fetch_object($result)){
  $i++;
  $form['book-'.$i] = array(
    '#type' => 'fieldset',
    '#title' => '<strong>'.l($n->title, "node/$n->nid").'</strong>',
    '#prefix' => '',
    '#suffix' => '',
    '#collapsible' => FALSE,
    '#weight' => $i,
  );
  $form['book-'.$i]['content'] = array(
    '#value' => book_tree($n->nid, 5),
  );
}
$output = drupal_render($form);
print $output;
?>

第二种:

< div class="book_tree" style="padding:0 0 0 30px"><ul>
<?php

$result = db_query('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = 0 order by n.changed');
while( $n = db_fetch_object($result)){
$output .= '<li>'.l($n->title, "node/$n->nid").'</li>';
$output .= book_tree($n->nid, 5);
}
print $output;

?>
</ul>< /div >

下面与第二段大致相同,只是改了排序方式:

< div class="book_tree" style="padding:0 0 0 30px"><ul>
<?php

$result = db_query('SELECT n.nid, n.title, b.parent FROM {node} n INNER JOIN {book} b ON n.vid = b.vid WHERE b.parent = 0 order by b.weight');
while( $n = db_fetch_object($result)){
$output .= '<li>'.l($n->title, "node/$n->nid").'</li>';
$output .= book_tree($n->nid, 5);
}
print $output;

?>
</ul>< /div >

第四种是官方的样式之一:

<?php
$book_top_page = 159;
$levels_deep = 2;
$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="expanded">';
          $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();


// use this version for Drupal 4.6
// $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'));

// use this version for Drupal 4.7 and Drupal 5
$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 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 book_struct_recurse($book_top_page, $levels_deep, $children, $current_lineage, $emulate_book_block);
?>

第五种是官方的样式之二:

<?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>";
?>