linlu11 的博客

drupal theme:按照内容类型设计页面布局

drupal theme:按照内容类型设计页面布局

源文: Customising the full page layout and sections based on node type
翻译: Evance | drupal theme:按照内容类型设计页面布局
说明:
这篇文章介绍如何根据不同的内容类型(content types)进行页面布局(full page layout)。比如说你想让你的blog和books拥有不同的外观。

步骤:
作为一个示例,下面一步一步演示一下如何为网站的blogs,books和首页(front page)拥有不同的页面布局。

首先:

1. 复制page.tpl.php文件一份副本,将它重命名为page-default.tpl.php
2. 再做几次相同的工作,分别将其命名为"page-front.tpl.php", "page-blog.tpl.php" 和 "page-book.tpl.php" 等等
3. 使用编辑器,修改每一个tpl.php文件,按照你的要求进行修改页面布局
4. 将修改后的tpl-type.php文件(page-front.tpl.php , page-blog.tpl.php 等等)上传到你正在使用的themem目录下

然后:

1. 用下面这段代码替换page.tpl.php中的内容
2. 确保theme内有page-default.tpl.php文件
3. 上传page.tpl.php文件到你现在正在使用的theme目录内,新的页面而已就会自动生效了

Evance注:

1. 下面的代码片断可以按照新增加/删减的内容类型进行添加/删除。
2. page-default.tpl.php文件将会是未指定特定内容类型的布局文件所默认的布局,比如说,按照前期设计要求完成了theme设计。后来可能根据新的需求又增加了新的内容类型,那么它将会使用page-default.tpl.php的布局进行页面组织。

<?php
/**
* This snippet loads up different page-type.tpl.php layout
* files automatically. For use in a page.tpl.php file.
*
* This works with Drupal 4.5, Drupal 4.6 and Drupal 4.7
*/

if ($is_front) {/* check if it's the front page */
include 'page-front.tpl.php'; /*load a custom front-page.tpl.php */
return; }

if (
$node->type == 'book') {/* check if it's a book page */
include 'page-book.tpl.php'; /*load a page-book.tpl.php */
return; }

if (
$node->type == 'blog') {/* check if it's a blog node */
include 'page-blog.tpl.php'; /*load page-blog.tpl.php */
return; }

if (
$node->type == 'image') {/* check if it's an image node */
include 'page-image.tpl.php'; /*load page-image.tpl.php */
return; }

if (
$node->type == 'forum') {/* check if it's a forum node */
include 'page-forum.tpl.php'; /*load page-forum.tpl.php */
return; }

include
'page-default.tpl.php'; /*if none of the above applies, load the page-default.tpl.php */
return;
?>

源文:

description

This explains how to customise the entire page layout depending on the node type. An example application is if you wanted your entire blog pages to look different to your book pages.
usage

As an illustrative example, the following step-by-step approach shows you how to setup different (full) page layouts for your blogs, books and the front page to your site.
Step 1 of 2

1. make a copy of your page.tpl.php file and rename it to be page-default.tpl.php.
2. make further copies your page.tpl.php file it and rename them to be page-front.tpl.php, page-blog.tpl.php and page-book.tpl.php etcetera..
3. using a text editor like notepad.exe or equivalent, modify the layout of each tpl.php file to suit your desires
4. upload your new page-type.tpl.php layout files to your active theme folder

Step 2 of 2

1. Using a text editor like notepad.exe or equivalent, replace the contents of your page.tpl.php file with the snippet below
2. Ensure that you have a page-default.tpl.php file as part of your collection of layouts.
3. Upload your new page.tpl.php file to your active theme folder and your new layouts will take effect automatically

谢谢 Evance

谢谢 Evance 大大的分享!~

------------------------------------

我的Drupal小站:www.boygj.com

Drupal小站:http://boygj.com/

"这篇文章介绍如果

"这篇文章介绍如果根据不同的内容类型"
"如果"-->"如何"。 :-)

--
proxomitron中文站

呵呵,感谢哈。打错

呵呵,感谢哈。打错字儿了..晕.

这样很直观啊,不错

这样很直观啊,不错!

---------------------------------------------
ShaoXing绍兴聚网

---------------------------------------------
ShaoXing绍兴聚网

不知道5.3版本的可以用不可以用

不知道5.3版本的可以用不可以用

5.x通用... 呵呵,放心

5.x通用...
呵呵,放心了...

多谢Evance了,这个确

多谢Evance了,这个确实是论坛上常见的问题。

这段代码适用于4.X版

这段代码适用于4.X版本,如果是5.X版本,就不用写这个代码了,可用直接在theme里面新定义一个页面。比如blog可用直接用page-blog.tpl.php来设定,drupal会自动搜索进入这个页面的。

tpl文件最烦人了。

很直观,很好用^^

很直观,很好用^^

可以简单些,更通用

可以简单些,更通用些:
1.将page.tpl.php重命名为page-default.tpl.php。
2. 创建新的page.tpl.php文件,代码如下:

<?php
if (isset($node))
{
$template_file = 'page-' . $node->type . '.tpl.php';
if (
file_exists(path_to_theme() . $template_file))
{
include
$template_file;
return;
}
}
include
'page-default.tpl.php';
?>

即可。
--------------------------------------------
欢迎访问Dr.Fang's Drupal Chanel
http://doctor-fang.blogspot.com/

欢迎访问Dr.Fang's Drupal Chanel
http://doctor-fang.blogspot.com/

好像并不成功啊。文件路径不对吧?是不是还要加上。bas

好像并不成功啊。

判断文件的路径不对吧。

--------!~~~本站只专注制作Drupal模板~~~~!---------

专注制作Drupal模板

Del.icio.us : drupal theme

posted on 2009-11-09 22:57  linlu11  阅读(607)  评论(0编辑  收藏  举报

导航