我是一个节点-MyContentType.tpl,我希望能够“打印”一个特定的词汇表。
换句话说,我想要那样的东西:
<Title>
<Vocabulary [1]>
<Body>
<Vocabulary [2]>
我认为这应该相当容易,但我正在努力...... 理想情况下,我希望将参数传递给:
希望有人可以帮助我,谢谢。
这是我到目前为止所做的:
<?php
foreach ( (array)$node->taxonomy as $term ) {
// $term->name has the taxonomy term name
// $term->tid has the taxonomy term id
$TermTitle = $term->name;
$TermDescription = $term->description;
print ($TermTitle);
print $TermDescription;
}
?>
现在,有人可以帮助我,这样只打印一个特定的词汇表,谢谢。
答案 0 :(得分:1)
Taxonomy Hide模块为您提供了一些奇特的配置,用于隐藏显示中的词汇表和术语。除非您的复杂用例可能会随着时间的推移而发生变化,否则您可能需要对其进行硬编码。
请查看taxonomy_hide_nodeapi()
,了解如何根据自己的需要进行调整。有趣的片段:
foreach ($node->taxonomy as $key => $value) {
if (array_key_exists($value->vid, $hidden)) {
unset($node->taxonomy[$key]);
答案 1 :(得分:0)
另一个简单的解决方案是你可以使用分类树模块download here,然后它会从那里读取QUICKSTART文件以了解如何创建树minue,转到块,你会找到该菜单的块,在任何地方显示它需要。 (如果有错误消息,则以正确的名称重命名该块) 。
答案 2 :(得分:0)
我会使用Views。
导入此视图以开始
$view = new view;
$view->name = 'taxonomy_terms2';
$view->description = '';
$view->tag = '';
$view->view_php = '';
$view->base_table = 'term_data';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
'name' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'link_to_taxonomy' => 0,
'exclude' => 1,
'id' => 'name',
'table' => 'term_data',
'field' => 'name',
'relationship' => 'none',
),
'phpcode' => array(
'label' => '',
'alter' => array(
'alter_text' => 0,
'text' => '',
'make_link' => 0,
'path' => '',
'link_class' => '',
'alt' => '',
'prefix' => '',
'suffix' => '',
'target' => '',
'help' => '',
'trim' => 0,
'max_length' => '',
'word_boundary' => 1,
'ellipsis' => 1,
'html' => 0,
'strip_tags' => 0,
),
'empty' => '',
'hide_empty' => 0,
'empty_zero' => 0,
'value' => '<?php
$term_link = \'taxonomy/term/\'.$data->tid;
if (arg(0)==\'node\') { // If we\'re on a node, get the node\'s term and compare it to this term
$node = node_load(arg(1));
foreach ($node->taxonomy as $term) {
if ($data->tid == $term->tid) {
$extra_class = "active-term";
}
}
} else if (arg(0)==\'topic\') { // If we\'re on a view, compare the first two arguments of the view\'s alias to the term\' alias
if(drupal_lookup_path(\'alias\', $term_link) == arg(0) . \'/\' . arg(1)) {
$extra_class = "active-term";
}
}
print l($data->term_data_name, $term_link, array(\'attributes\' => array(\'class\' => $extra_class)));
?>',
'exclude' => 0,
'id' => 'phpcode',
'table' => 'customfield',
'field' => 'phpcode',
'relationship' => 'none',
),
));
$handler->override_option('sorts', array(
'weight' => array(
'order' => 'ASC',
'id' => 'weight',
'table' => 'term_data',
'field' => 'weight',
'relationship' => 'none',
),
));
$handler->override_option('filters', array(
'vid' => array(
'operator' => 'in',
'value' => array(),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'vid',
'table' => 'term_data',
'field' => 'vid',
'relationship' => 'none',
'override' => array(
'button' => 'Override',
),
),
));
$handler->override_option('access', array(
'type' => 'none',
));
$handler->override_option('cache', array(
'type' => 'none',
));
$handler->override_option('footer_format', '5');
$handler->override_option('footer_empty', 0);
$handler->override_option('style_plugin', 'list');
$handler->override_option('style_options', array(
'grouping' => '',
'type' => 'ul',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('filters', array(
'vid' => array(
'operator' => 'in',
'value' => array(
'49' => '49',
),
'group' => '0',
'exposed' => FALSE,
'expose' => array(
'operator' => FALSE,
'label' => '',
),
'id' => 'vid',
'table' => 'term_data',
'field' => 'vid',
'relationship' => 'none',
'override' => array(
'button' => 'Use default',
),
),
));
$handler->override_option('block_description', '');
$handler->override_option('block_caching', -1);
然后选择你的词汇
答案 3 :(得分:0)
我用它来打印词汇表id匹配1的分类法名称。它是硬编码的,但它足以满足我的需要。
// Print the Product Type
// Print Taxonomy terms where vid == 1
foreach ($node->taxonomy as $key => $value) {
if ( $node->taxonomy[$key] -> vid == 1) {
print ( $node->taxonomy[$key] -> name );
}
}