在theme里区别显示一般分类与freetag标签

本文介绍了一个用于改进Drupal站点中节点模板的PHP函数。该函数通过遍历节点的分类术语并重新组织它们来增强显示效果,确保词汇表按ID排序,并使用主题函数呈现术语链接列表。此外,还介绍了如何移除旧的术语变量并创建新的格式化后的术语变量以提高用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

add this function to template.php


function phptemplate_preprocess_node(&$vars) {
// If we have any terms...
if ($vars['node']->taxonomy) {
// Let's iterate through each term.
foreach ($vars['node']->taxonomy as $term) {
// We will build a new array where there will be as many
// nested arrays as there are vocabularies
// The key for each nested array is the vocabulary ID.
$vocabulary[$term->vid]['taxonomy_term_'. $term->tid] = array(
'title' => $term->name,
'href' => taxonomy_term_path($term),
'attributes' => array(
'rel' => 'tag',
'title' => strip_tags($term->description),
),
);
}
// Making sure vocabularies appear in the same order.
ksort($vocabulary, SORT_NUMERIC);
// We will get rid of the old $terms variable.
unset($vars['terms']);
// And build a new $terms.
foreach ($vocabulary as $vid => $terms) {
// Getting the name of the vocabulary.
$name = taxonomy_vocabulary_load($vid)->name;
// Using the theme('links', ...) function to theme terms list.
$terms = theme('links', $terms, array('class' => 'links inline'));
// Wrapping the terms list.
$vars['terms'] .= '<div class="vocabulary taxonomy_vid_';
$vars['terms'] .= $vid;
$vars['terms'] .= '">';
$vars['terms'] .= $name;
$vars['terms'] .= ': ';
$vars['terms'] .= $terms;
$vars['terms'] .= '</div>';
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值