找到theme所在的目录中的template.php文件(如果没有可以自己增加一个。)
8 p$ F5 m, J4 d& b: c# g: a! Z% x在里面添加一段:
; o* ^' w3 P, }7 u& C
, h7 b, @# D( {* I: B<?php+ I( l& u" w1 I0 A+ k9 }: b0 v
function phptemplate_preprocess_page(&$variables) {; y9 W/ J7 X2 i8 x" V
if ($node = menu_get_object()) { } m; _/ T/ y4 V7 a
$variables['node'] = $node;
/ ]# P7 T1 N, N# E$suggestions = array();
4 F/ @9 u$ G% H. l0 G/ Q o7 P$template_filename = ‘page’;
' \0 m/ _4 }) u: l$template_filename = $template_filename . ‘-’ . $variables['node']->type;: k) L d8 H) }7 K( ?! C; N
$suggestions[] = $template_filename;% _# Z6 j" H8 c, D
$variables['template_files'] = $suggestions;1 H: g0 i) m9 b) V4 \& R
}
3 n6 t$ j* C' i}
3 h+ P9 V* i5 C5 E?>( l: N+ Y; O1 O! q% p8 e
' j5 l/ N* ?/ ^% A$ g
代码添加完毕之后,只需为不同的node type建议不同的layout文件到theme目录即可了,如:/ F* I$ o/ C3 h# b, y+ b) C' ~# A6 L
forum -> page-forum.tpl.php# L' Y; @+ h% s7 U" G! Y
blog -> page-blog.tpl.php
N5 g9 [. L( I2 t9 @book -> page-book.tpl.php
5 x) z4 `2 Z: s5 Q( e& a$ h
; v! |$ w& i, @$ \- A. d( |8 ?/ [+ A! E0 C7 J- b4 o7 j; L8 X
本文选自:滴水穿石,谢谢!4 P+ o' s; V, }7 r: ]5 `! P
. u' Y- R& K: S3 F! D
* | z1 I5 _& W, H7 M4 p$ o* ]
0 `$ | y* _7 k4 e
; ?! M+ }; O" b& `
& \$ _: d/ Q% S( \ |