2

我正在为 node-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;
}
?>

现在,有人可以帮我这样只打印一个特定的词汇,谢谢。

4

4 回答 4

1

Taxonomy Hide模块为您提供了一些精美的配置,用于隐藏词汇表和术语以使其不显示。除非您有一个可能随时间变化的复杂用例,否则您可能需要对其进行硬编码。

看看taxonomy_hide_nodeapi()以了解如何调整它以满足您的需求。有趣的片段:

foreach ($node->taxonomy as $key => $value) {
  if (array_key_exists($value->vid, $hidden)) {
    unset($node->taxonomy[$key]);

于 2009-09-28T04:05:23.867 回答
0

我会为此使用视图。

导入此视图以开始

$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);

然后选择你的词汇

于 2011-01-11T21:23:45.430 回答
0

另一个简单的解决方案是您可以使用分类树菜单模块 下载here,然后它将从那里读取QUICKSTART文件以了解如何创建树minue,转到块,您将找到该菜单的块,将其显示在您需要的任何地方。(如果有错误消息,请用正确的名称重命名块)。

于 2010-02-28T06:30:58.533 回答
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 );
  }
}
于 2012-05-18T01:40:01.780 回答