找到theme所在的目录中的template.php文件(如果没有可以自己增加一个。)
. h) M, {9 x4 S( n, R! Y" l5 s( A在里面添加一段:% H% V; O$ C1 z- _" r
0 z, z1 ?; w/ x* M0 z1 ?9 _- r<?php: X4 r' |1 x0 P$ y
function phptemplate_preprocess_page(&$variables) {3 V7 e6 l# K7 P
if ($node = menu_get_object()) {
- H! v/ S" y# i% w9 `# u" \3 `$variables['node'] = $node;
: Q( E R3 I3 o! u$ h) ]( M$ B$suggestions = array();
7 O( X; U/ S7 m4 |. I. U$template_filename = ‘page’;9 e9 a8 E# Q" c. @* G
$template_filename = $template_filename . ‘-’ . $variables['node']->type;
; d; y) E2 _/ z* v7 ~8 ~$suggestions[] = $template_filename;$ c% }* I1 e) i b
$variables['template_files'] = $suggestions;
: s6 W' |/ A5 g o' n, ~}- U! P1 b; d* m. y% z$ a: G
}
% B ]+ R1 _) t: ~ {2 i?>1 a m% B' D7 a& \& @- W! r4 ]" K8 v' \
}2 h% J- t8 a) O- k3 e. g
代码添加完毕之后,只需为不同的node type建议不同的layout文件到theme目录即可了,如:0 r! E! ^. _8 }/ I7 B
forum -> page-forum.tpl.php# z. t! r- G3 F1 u
blog -> page-blog.tpl.php9 ?5 Q. @8 W" t3 |( F8 K( v
book -> page-book.tpl.php, ~5 Y! l* `6 V! K ^- p) @
, t4 n. K# ^, J) R4 S: p
) c3 x& _5 E d9 T% A9 h. d本文选自:滴水穿石,谢谢!- F8 @8 ~2 W8 S- A2 I# J
( V: L* z; m1 s6 v- D0 g9 \- R; b! j# [$ U' W
2 M+ X' s4 i; d4 Y& d0 e& f' H% G, H" h. o% q4 u7 p4 o1 O% m
7 O% _( X# r3 U3 R0 f
|