渲染分类法页面D7的自定义字段

时间:2012-04-25 07:39:21

标签: drupal-7 taxonomy

假设我有一个名为“职位名称”的词汇表。该词汇表包含多个自定义字段。

"JOB TITLES" (Vocabulary)
 |
 |-- name (Default Field)
 |-- description (Default Field)
 |-- reference_url (Custom Field)
 |-- help_link (Custom Field)

以上词汇表包含2个自定义字段,我可以在添加或编辑分类术语时看到这些字段。

我的问题是,如何在我的page.tpl上使用它们?如何使用hook_page_preprocess()?

在template.php上访问它们

2 个答案:

答案 0 :(得分:0)

不幸的是,我还没有找到一个好的解决方案。我解决了暂时所以:

自定义字段:

$output = (isset($term->field_FIELDNAME['und'][0]['safe_value']))? $term->field_FIELDNAME['und'][0]['safe_value'] : '' ;

条款说明:

$output = filter_xss_admin($term->description);

$ term是:

$tid = (int)arg(2);
$term = taxonomy_term_load($tid);

我再说一遍,上面的自定义字段解决方案不是最佳做法,也是不可预测的,因此请谨慎使用。

答案 1 :(得分:0)

要在术语页面底部显示文本,我在分类词汇表中添加了2个新字段('field_term_heading'和'field_term_footer')。我发现它创建了一个相当笨拙的嵌套数组。这是我添加到page.tpl.php以显示它。

<?php if ( arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) ): ?>

    <?php $page_term = taxonomy_term_load(arg(2));
        if ($page_term->field_footer_heading) {
        print '<h2 class="block-title">'.($page_term->field_footer_heading['und'][0]['safe_value']).'</h2>';
        }
    ?>
    <?php $page_term = taxonomy_term_load(arg(2));
        if ($page_term->field_footer_text) {
        print '<div class="content">'.($page_term->field_footer_text['und'][0]['safe_value']).'</div>';
        }
    ?>

    <?php endif; ?>