日期:2015-02-09 阅读:3830
dmandwp系统 - wordpress系统和DM系统区块建站>>
来源 : http://www.wdtutorials.com/2012/09/11/drupal-7-and-drupal-6-how-print-taxonomy-terms-templates
不错的一遍文档。
In node template:
<?php
print render($content['field_tags']);
?>
If you want just the names:
<?php
if (!empty($node->field_tags)) {
foreach($node->field_tags['und'] as $tag) {
print $tag['taxonomy_term']->name;
}
}
?>
If you want terms from certain vocabulary:
<?php
if (!empty($node->field_tags)) {
$your_vocabulary_name = 'tags';
foreach($node->field_tags['und'] as $tag) {
if ($tag['taxonomy_term']->vocabulary_machine_name == $your_vocabulary_name) {
print $tag['taxonomy_term']->name;
}
}
}
?>
In Views --views这个功能,有点陌生,可参考的不多。
(If you have Content: All taxonomy terms field )
<?php
print render($fields['term_node_tid']->content);
?>
(You can disable the links or limit terms by vocabulary inside the Views user interface)--意思就是有些动作可以在views的后台来操作,比如取消链接或限制术语等。
=============
有时用人工桥的方式,一些字段不大好导出来,这时就要用views的字段输出功能,具体参考:
http://drupal.stackexchange.com/questions/73999/get-field-value-directly-from-inside-views-view-list-tpl-php
以前提到过,覆写views,除了我们的一招制胜外,还有就是三个文件。
views-view-list.tpl.php file it's a view template to display a list of rows, not fields.
Theming only fields:
<?php foreach ($fields as $id => $field): ?>
<li><?php print $field->content; ?></li>
<?php endforeach; ?>
* file: views-view-fields--[view name]--[display].tpl.php
Theming the whole output:
<div class="<?php print $classes; ?>">
<?php foreach ($view->style_plugin->rendered_fields as $delta => $item): ?>
<li><?php print $item['field_my_field_name']; ?></li>
<?php endforeach; ?>
</div>
* file: views-view--[view name]--[display].tpl.php
===============
如果不想覆写,也可以在后台views使用Global text或者views php。把其他字段exclude不显示。
===