`

将taxonomy输出为菜单

阅读更多
<?php
            // The ID of the taxonomy vocabulary for which you'd like to create a nested list
            $vid = 10;
            $depth = 0;
            $num_at_depth = 0;
            $tree = taxonomy_get_tree($vid);
            print "<ul class="menu">\n<li>";
            foreach ($tree as $term) {
            $diffdepth=0;
              if ($term->depth > $depth) {
                print "\n<ul>\n<li>";
                $depth = $term->depth;
                    $num_at_depth = 0;
              }
              if ($term->depth < $depth) {
                $diffdepth= $depth -$term->depth;
                while ($diffdepth > 0){
                    print "</li>\n</ul>\n";
                    $diffdepth -- ;
                }
                    $depth = $term->depth;
              }
              if (($term->depth == $depth) && ($num_at_depth > 0)) {
                  print "</li>\n<li>";
                }
              print l($term->name, 'taxonomy/term/' . $term->tid);
                $num_at_depth ++;
            }
            print "</li>\n</ul>\n";
?>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics