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);}
?>
23 小时 11 分钟之前
2 天 4 小时之前
6 天 7 小时之前
1 周 2 天之前
1 周 2 天之前
1 周 3 天之前
1 周 4 天之前
2 周 9 小时之前
3 周 1 天之前
4 周 3 小时之前