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

もう 1 つの簡単な解決策は、タクソノミー treemenu モジュール のダウンロードを使用して、そこから QUICKSTART ファイルを読み込んでツリー分を作成する方法を知ることです。ブロックに移動すると、そのメニューのブロックが見つかり、必要な場所に表示されます。(エラー メッセージがある場合は、ブロックの名前を正しい名前に変更します)。

于 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 に答える
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 に答える