国外设计欣赏网站 - DOOOOR.com

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,微信登陆

搜索

[Drupal问题] 根据内容类型定制drupal模板

[复制链接]
发表于 3-21-2012 18:42 | 显示全部楼层 |阅读模式
找到theme所在的目录中的template.php文件(如果没有可以自己增加一个。)% E3 ?9 c+ _1 X( G3 W
在里面添加一段:  x8 E3 g+ o4 H4 S. O

4 u7 {; \. |$ i& X<?php
5 x6 l3 K9 `; Nfunction phptemplate_preprocess_page(&$variables) {
3 w$ M" c* ^* u! Q* v, i! ~if ($node = menu_get_object()) {1 V3 a+ {# Z1 X7 @
$variables['node'] = $node;
2 I5 V2 k+ O4 d  e+ a$suggestions = array();% K& o' J  R$ U% H$ h5 Q5 Y
$template_filename = ‘page’;- {) C& A. L/ ?5 b; g
$template_filename = $template_filename . ‘-’ . $variables['node']->type;) v4 n* s4 j* v6 v  V+ Q
$suggestions[] = $template_filename;) X8 a% m9 b4 B
$variables['template_files'] = $suggestions;6 Z$ C( e. a9 O4 t; w
}! Y& I: b; P1 j; `  _, E0 ^" [7 k
}
( S- I7 e: ^) B* Q. R" D0 I9 J6 G6 q?>' k) k/ h5 S3 t7 `, T4 h( M% W7 r
  w2 @3 P& q: L
代码添加完毕之后,只需为不同的node type建议不同的layout文件到theme目录即可了,如:
+ p( n! d; f! b* u6 s5 @+ c7 j  Rforum -> page-forum.tpl.php
6 [* C$ N7 b6 M2 u- y8 }blog -> page-blog.tpl.php5 |& f( _- R# J2 q  g& u5 r
book -> page-book.tpl.php0 x; x: t: o  |1 _9 l9 {
& C& g- x" P5 f5 }5 U
3 i9 \( B6 z0 w% @4 I
本文选自:滴水穿石,谢谢!
! r6 T2 {3 c( P8 B" Z6 S/ t) V+ b: r, w# u4 g: U; b/ ]+ Z" M# C

1 o. Q, [2 Q1 x2 O; Y0 f& _2 Y/ M
7 G- p' y& ]& A2 c
4 \9 \0 X* X1 l5 w8 w' l  M

|2011-2026-版权声明|平台(网站)公约|DOOOOR 设计网 ( 吉ICP备2022003869号 )

GMT+8, 6-19-2025 10:32 , Processed in 0.317125 second(s), 60 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表