开发者

different tag using different template file according to the content type?

开发者 https://www.devze.com 2023-02-16 10:04 出处:网络
i want to using the taxonomy pagetemplate according t开发者_运维技巧o the content type? namely, the tag under content type \"story\" using a tpl.php, and the tag under the content page, using another

i want to using the taxonomy page template according t开发者_运维技巧o the content type? namely, the tag under content type "story" using a tpl.php, and the tag under the content page, using another tpl.php file. how should i do?thank you.


In template.php of your theme:

/**
 * Override or insert variables into the page templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 */
function YOURTHEMENAME_preprocess_page(&$vars) {
  // ...
  $node = $vars['node'];
  if ($node && ($node->type=='story')) {
    foreach ($node->taxonomy as $term) { 
      if ($term->name == 'SOMETAG1') {
        $vars['template_files'][] = 'page-sometag1';
        break;
      }
      else if ($term->name == 'SOMETAG2') {
        $vars['template_files'][] = 'page-sometag2';
        break;
      }
    }
  }
  // ...
}

Replace uppercase with your values. page-sometag1.tpl.php and page-sometag2.tpl.php files should be in your theme folder.


The ThemeKey module might do this.

(Not sure it can work with both content-type and taxonomy term in the same condition ; but I've seen it used a couple of times to change templates / themes bases on some conditions)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号