【问题标题】:Drupal 7: How to create one node page for multiple content types?Drupal 7:如何为多种内容类型创建一个节点页面?
【发布时间】:2013-09-23 06:27:51
【问题描述】:

我的网站中有 8 种内容类型,其中 4 种具有相同的结构,不同之处只是它们的名称。我想为他们创建一个节点页面,但我想为每个页面创建一个 .tpl.php 文件效率低下。我使用以下方法为某种内容类型创建节点页面:

  1. 创建页面并重命名为page--node--Machine-Name-of-ContentType.tpl.php

  2. 将此函数添加到template.php

    function ThemeName_preprocess_page(&$variables) {

    if (isset($variables['node'])) 
    {
        $suggest = "page__node__{$variables['node']->type}";
        $variables['theme_hook_suggestions'][] = $suggest;
    }
    

    }

有没有办法为多种内容类型创建一个节点页面?

【问题讨论】:

    标签: templates preprocessor content-type


    【解决方案1】:
    function theme_preprocess_page(&$vars) {
      if (isset($vars['node']->type)) {
        switch ($vars['node']->type) {
          case 'news':
          case 'blog':
          case 'event':
          case 'page':
            $vars['theme_hook_suggestion'] = 'page__alt';
            break;
        }
    }
    

    将使用页面--alt.tpl.php 文件

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-13
      • 2011-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-01
      相关资源
      最近更新 更多