我想使用 Drupal Nice Menus来显示某些书籍或任何级别的子书籍,但看不到theme_nice_menus函数将如何做到这一点。
我正在查看下面的代码示例以获得一些灵感:
第一个示例适用于所有书籍,但我需要传递选定的书籍,甚至是子书。
第二个示例适用于一本书,但不使用漂亮的菜单?可以将输出menu_tree_all_data
或menu_tree_output
传递给theme_nice_menus
函数吗?
第三个来自github 上的bookoblock模块,它显示了如何获取一本书,而不是从其孩子那里获取子书,并且不使用漂亮的菜单。
我正在尝试创建这些示例中的一些内容。从子书而不是顶级书生成菜单是我想做的一件事。
<?php
$master_menu = '';
$books = book_get_books();
foreach($books as $book_nid=>$book) {
$menu = theme('nice_menus', array('id' => $book['mlid'], 'direction' => 'right', 'depth' => -1, 'menu_name' => $book['menu_name'], 'menu' => NULL));
$master_menu .= $menu['content'];
}
print $master_menu;
?>
<?php
$book_top_page= 49;
$tree = menu_tree_all_data(book_menu_name($book_top_page));
print drupal_render(menu_tree_output($tree));
?>
<?php
function bookoblock_block_view() {
if ($book = bookoblock_is_book_node()) {
// menu_build_tree() doesn't accept zero for depth, so we convert that to
// NULL and add 1 if it's not 0 to account for the first (skipped) level.
$max_depth = variable_get('bookoblock_depth', NULL);
$max_depth = ($max_depth == 0) ? NULL : ($max_depth + 1);
// Vars and params for the menu_build_tree() function.
$path = 'node/' . $book['bid'];
$parent = menu_link_get_preferred($path, book_menu_name($book['bid']));
$parameters = array(
'only_active_trail' => FALSE,
'min_depth' => $parent['depth'] + 1,
'max_depth' => $max_depth,
);
// Build the tree and block title.
$children = menu_build_tree($parent['menu_name'], $parameters);
$book_name = (book_toc($book['bid'], 1));
// Build and return the $block array.
$block['subject'] = l($book_name[$book['p1']], 'node/' . $book['bid']);
$block['content'] = menu_tree_output($children);
return $block;
}
// If the current node isn't part of a book, just return nothing.
return NULL;
}
?>