Drupal 7 在page.tpl drupal 7上打印特定词汇中的术语
我以前在drupal 6上有一个功能,可以通过加载特定vocab中的所有术语来创建自定义菜单:Drupal 7 在page.tpl drupal 7上打印特定词汇中的术语,drupal-7,Drupal 7,我以前在drupal 6上有一个功能,可以通过加载特定vocab中的所有术语来创建自定义菜单: function _taxonomy_top_links($vid = NULL) { $terms = taxonomy_get_tree($vid); $taxos = array(); foreach ($terms as $term) { $taxos[] = array('title' => $term->name, 'taxonomy/term/' . $
function _taxonomy_top_links($vid = NULL) {
$terms = taxonomy_get_tree($vid);
$taxos = array();
foreach ($terms as $term) {
$taxos[] = array('title' => $term->name, 'taxonomy/term/' . $term->tid, 'attributes' => array('rel' => 'tag', 'title' => strip_tags($term->description)));
}
return theme('links', $taxos, array('id' => 'menu-'. $vid, 'class' => 'menu clearfix'));
}
这在Drupal7上不起作用,我想这与新的FieldAPI有关。如何从一个特定的vocab中获取所有术语,以便在页面级别进行预处理
感谢您的帮助。您的大部分代码实际上应该可以正常工作,但主题部分不正确
$terms = taxonomy_get_tree($vid, 0, NULL, TRUE);
$links = array();
foreach ($terms as $term) {
$uri = entity_uri('taxonomy_term', $term);
$link = array(
'title' => $term->name,
'href' => $uri['path'],
'attributes' => array('rel' => 'tag'),
);
$link += $uri['options'];
if (!empty($term->description)) {
$link['title'] = strip_tags($term->description);
}
$links['tid-' . $term->tid] = $link;
}
$variables = array(
'links' => $links,
'attributes' => array(
'id' => 'menu-' . $vid,
'class' => array('menu', 'clearfix'),
),
);
return theme('links', $variables);
你的大部分代码实际上应该可以正常工作,但主题部分是不正确的
$terms = taxonomy_get_tree($vid, 0, NULL, TRUE);
$links = array();
foreach ($terms as $term) {
$uri = entity_uri('taxonomy_term', $term);
$link = array(
'title' => $term->name,
'href' => $uri['path'],
'attributes' => array('rel' => 'tag'),
);
$link += $uri['options'];
if (!empty($term->description)) {
$link['title'] = strip_tags($term->description);
}
$links['tid-' . $term->tid] = $link;
}
$variables = array(
'links' => $links,
'attributes' => array(
'id' => 'menu-' . $vid,
'class' => array('menu', 'clearfix'),
),
);
return theme('links', $variables);
对不起,回来晚了。我使用了taxonomy_菜单,但我需要更大的灵活性,使其表现得像一个过滤器,并避免重建。这很有魅力。谢谢。很抱歉回来晚了。我使用了taxonomy_菜单,但我需要更大的灵活性,使其表现得像一个过滤器,并避免重建。这很有魅力。谢谢