如何为分类/术语/x 页面设置主题?

发布于 2024-08-29 08:06:02 字数 93 浏览 8 评论 0原文

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

我该怎么做呢?

Although it was easy to find some info online about how to theme other stuff (e.g. search results), it is impossible to find a straightforward article about how to theme the output of a taxonomy/term/247 page?

How can I do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

遮了一弯 2024-09-05 08:06:02

在 Drupal 6 中,您可以使用主题中的 node-taxonomy.tpl.phppage-taxonomy-term.tpl.php 文件来模板分类页面,考虑到第二个是第一个的包装。 node-taxonomy.tpl.php 的行为类似于 node.tpl.phppage-taxonomy-term.tpl.php 类似于 page .tpl.php。例如:

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>

嗯,最重要的部分:默认情况下节点分类。 Drupal 不知道 tpl.php,因此我们需要在主题的 template.php 文件中将其作为模板建议引入,如下所示:

/**
 * 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);
  }
}

还有一个 taxonomy- term.tpl.php,关于 Drupal 7。
这是一个代码示例,不要忘记使用 check_plain() &打印输出上的check_url()

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.

痴梦一场 2024-09-05 08:06:02

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

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

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

The taxonomy page is not magic in any that it requires something special to theme it. There's a template file, a preprocess function and some theming functions, much like any page.

If you would like to control the output of the default taxonomy page which is a bit raw, you can use views to overwrite the default page. You could then use views to only show node teasers, do some custom ordering, use a pager etc.

If you want to do something more specific you should edit your question to tell us what you want to do.

柠檬色的秋千 2024-09-05 08:06:02

您最好在 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

You better use following code in template.php

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

Because you can use file names such as node-term-YOUR-TERM-ID.tpl.php for each term .

if you want to make it more efficient use :

  if ($hook == 'node') {
       if (arg(0) == 'taxonomy') { 
        foreach ($vars['node']->taxonomy as $term) {
        $vars['template_files'][] = 'node-term-'. $term->tid;
       }
    }
  } //if bracket close
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文