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

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,微信登陆

搜索

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

[复制链接]
发表于 3-21-2012 18:42 | 显示全部楼层 |阅读模式
找到theme所在的目录中的template.php文件(如果没有可以自己增加一个。)
! g7 Z- y, X# E在里面添加一段:6 G1 w7 ?- ^7 y9 r3 v1 Z
& @6 h  d1 R- x2 ~" ?* _# a: p) |
<?php
" I% j. T5 c1 f- P8 U" @/ ]" cfunction phptemplate_preprocess_page(&$variables) {9 K  p- z7 K# L6 [! }$ F
if ($node = menu_get_object()) {9 O+ Q: w! f! ?) e- _6 y
$variables['node'] = $node;
& B5 p- x9 \/ R. m! D% x) E- T! L8 W$suggestions = array();8 p( {. f' {" S: I
$template_filename = ‘page’;
& b' o! m: I0 o. x- \1 Q$template_filename = $template_filename . ‘-’ . $variables['node']->type;
) L- I4 {1 ?* K$suggestions[] = $template_filename;
% W+ V% L) _1 a9 H" O1 W$variables['template_files'] = $suggestions;
/ _; T  O; Z5 z}
( s$ R/ f0 n( O- p}
7 P6 ?, m* y% \7 z% i?>0 A, B  @8 |- h1 a/ r  V1 j; ]# F

' ?$ h! h1 f* [% f4 y  k代码添加完毕之后,只需为不同的node type建议不同的layout文件到theme目录即可了,如:3 ^4 |2 \5 A4 `0 ]! \6 ]& n* {
forum -> page-forum.tpl.php0 K- o- w- t" U. k. Q+ q
blog -> page-blog.tpl.php# P! n' x7 |' O% w, ?
book -> page-book.tpl.php9 b! g" o) U. a/ p# x
( [7 ~4 [9 o# i* Z  J+ H
" W' g3 c+ U4 _9 K/ H
本文选自:滴水穿石,谢谢!( V! u1 W9 u9 s# F: g/ A/ U7 ~

% U+ n+ g5 ~" C" f0 ~4 c

& `5 p& N2 J2 N/ Q7 @
) M( ?/ p" m. f

+ H% v8 W) i8 v7 g. w, n% [8 L8 }0 [  I% Q  y9 c8 i& z

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

GMT+8, 11-20-2025 02:33 , Processed in 0.259138 second(s), 60 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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