20

虽然很容易在网上找到一些关于如何为其他内容设置主题的信息(例如搜索结果),但要找到一篇关于如何为分类/术语/247 页面的输出设置主题的简单文章是不可能的?

我该怎么做?

4

3 回答 3

12

In Drupal 6, you can make use of node-taxonomy.tpl.php and page-taxonomy-term.tpl.php files in your theme to template taxonomy pages considering that the second one is the wrapper for the first. Behave node-taxonomy.tpl.php like node.tpl.php and page-taxonomy-term.tpl.php like page.tpl.php. for example:

page-taxonomy-term.tpl.php

<?php require 'header.tpl.php'; ?>
    <body class="<?php echo $body_classes; ?>">
        <div id="page">
            <?php require 'page-navigation.tpl.php'; ?>
            <div id="main">
        <h2>Taxonomy term page</h2>
        <div class="taxonomy-content">
            <?php if ($tabs): echo '<div id="tabs-wrapper" class="clear-block">'; endif; ?>
            <?php if ($title && !$node): echo '<h2'. ($tabs ? ' class="with-tabs"' : '') .'>'. $title .'</h2>'; endif; ?>
            <?php if ($tabs): echo '<ul class="tabs primary">'. $tabs .'</ul></div>'; endif; ?>
            <?php if ($tabs2): echo '<ul class="tabs secondary">'. $tabs2 .'</ul>'; endif; ?>
            <?php if ($show_messages && $messages){ echo $messages; } ?>
            <?php echo $help; ?>
            <?php echo $content; // contains the output of node-taxonomy.php, that's why I call this wrapper template file. ?>
        </div> <!-- #taxonomy-content -->                   
            </div> <!-- #main -->           
        </div> <!-- #page -->
        <?php echo $closure; ?>
    </body>
<?php require 'page-footer.tpl.php'; ?>

node-taxonomy.tpl.php

<div id="node-<?php echo $node->nid; ?>" class="node<?php if($sticky) echo ' sticky'; ?><?php if(!$status) echo ' node-unpublished'; ?>">
  <div class="taxonomy-node">
      <div class="node-body">
        <a class="node-title" href="<?php echo $node_url ?>" title="<?php echo $title ?>">
          <?php echo $title ?>
        </a>
        <span class="node-cck-field">
          <?php echo $node->field_cck_blah[0]['view']; ?>
        </span>                             
      </div>                
  </div>
</div>

Well, the most important part: By default the node-taxonomy.tpl.php is not known to Drupal, so we need to introduce this as a template suggestion in the our theme's template.php file, here we go:

/**
 * Adding custom PHPTemplate suggestions on taxanomy pages.
 *
 * @param $vars
 *   A sequential array of variables to pass to theme template.
 */
function phptemplate_preprocess_node(&$vars) {
  if(arg(0) == 'taxonomy'){
    $suggestions = array('node-taxonomy');
    $vars['template_files'] = array_merge($vars['template_files'], $suggestions);
  }
}

Also there is a taxonomy-term.tpl.php, regarding Drupal 7.
It's a code sample, dont' forget to use check_plain() & check_url() on printouts.

于 2010-04-18T10:01:32.843 回答
1

分类页面并不神奇,因为它需要一些特殊的主题。有一个模板文件、一个预处理函数和一些主题函数,就像任何页面一样。

如果您想控制有点原始的默认分类页面的输出,您可以使用视图覆盖默认页面。然后,您可以使用视图仅显示节点预告片、进行一些自定义排序、使用寻呼机等。

如果你想做更具体的事情,你应该编辑你的问题,告诉我们你想做什么。

于 2010-04-16T18:17:23.233 回答
1

您最好在 template.php 中使用以下代码

  foreach ($vars['node']->taxonomy as $term) {
    $vars['template_files'][] = 'node-term-'. $term->tid;
  }

因为您可以为每个 term 使用诸如 node-term-YOUR-TERM-ID.tpl.php 之类的文件名。

如果你想让它更有效地使用:

  if ($hook == 'node') {
       if (arg(0) == 'taxonomy') { 
        foreach ($vars['node']->taxonomy as $term) {
        $vars['template_files'][] = 'node-term-'. $term->tid;
       }
    }
  } //if bracket close
于 2012-08-31T20:15:15.253 回答