drupal技巧:设置像Wordpress的菜单

Wordpress在具有很好的菜单用户体验,如果需要在drupal中实现这样的效果,可以参考以下代码:

internet (5)
Google (1)
Yahoo (2)
Web 2.0 (1)
Misc (0)

<?php
$vid = 4;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term ) {
    $count = "(".db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)).")";
    $items[] = l($term->name, "taxonomy/term/$term->tid") . " $count";
}
if ( count($items) ) {  print theme('item_list', $items);}
?>

使用taxonomy_get_tree函数实现菜单列表
Internet (18)
-- Mail (8)
-- Web (10)
Graphic (52)
-- Photoshop (50)
-- Corel (1)
-- Flash (1)
Security (8)
-- Firewall (2)
-- Anti virus (6)

<?php
$vid = 4;  // Set the vid to the vocabulary id of the vocabulary you wish to list the terms from
$items = array();
$terms = taxonomy_get_tree($vid);
foreach ( $terms as $term )
{
  $count = "(".db_result(db_query("SELECT COUNT(nid) FROM {term_node} WHERE tid = %d", $term->tid)).")";
  $termdepth = "";
  for ($i=0;$i<$term->depth;$i++)
  {
    $termdepth = $termdepth . "-- ";
  }
  $items[] = $termdepth . l($term->name, "taxonomy/term/$term->tid") . " $count";
}
if ( count($items) ) {  print theme('item_list', $items);}
?>

同步内容