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

由 Evance 于 星期一, 2007-12-24 08:54 发表
源文: 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


if ($is_front) { 
include 'page-front.tpl.php'; 
return; }

if ($node->type == 'book') { 
include 'page-book.tpl.php'; 
return; }

if ($node->type == 'blog') { 
include 'page-blog.tpl.php'; 
return; }

if ($node->type == 'image') { 
include 'page-image.tpl.php'; 
return; }

if ($node->type == 'forum') { 
include 'page-forum.tpl.php'; 
return; }

include '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

你可能感兴趣的:(工作,PHP,Blog)