drupal 的简单模板修改

来源:互联网 发布:淘宝代运营服务项目 编辑:程序博客网 时间:2024/05/20 00:12

Drupal 页面的模板文件后缀名叫做"theme",和Windows的主题文件名一样,是直接用php写的,改起来比较困难,我在用 Drupal 架自己的这个 blog 用的是一种比较简单的方法。

先安装 Drupal site contributed theme - PHP Template,解开default目录里的文件是默认的模板样式,你可以直接修改default里文件,或者拷贝该文件夹重命名,然后在网站的phptemplate控制台选择新生成的文件夹。

default目录的templates文件夹放的是页面模板:

header.tpl.php, footer.tpl.php
分别是页面头尾,以内容节点为分隔,也就是把你写好的template的html从放content的点分开放在这两个文件里。并在需要的地方插入模块

search框
<?php if ($display_search): ?>

导航条
<?php if (is_array($links)): ?>
  <ul id="main-nav">
  <?php foreach ($links as $link): ?>
    <li><?php print $link?></li>
  <?php endforeach; ?>
  </ul>
<?php endif; ?>

左边的sidebar
<?php if ($sidebar_left != ""): ?>
  <div class="sidebar" id="sidebar-left">
    <?php print $sidebar_left ?>
  </div>
<?php endif; ?>

右边sidebar
<?php if ($sidebar_right != ""): ?>
  <div class="sidebar" id="sidebar-right">
    <?php print $sidebar_right ?>
  </div>
<?php endif; ?>

当前位置的导航条
<?php if ($breadcrumb != ""): ?>
  <?php print $breadcrumb ?>
<?php endif; ?>

不要忘了
<form action="<?php print url("search") ?>" method="post">
...
</form>

尽量使用div来写页面,使用table页面打开比较慢,且无法使用htmlarea模组。

node.tpl.php
内容节点模板,修改如内容标题日期的样式,在一个页面中重复使用。

default目录的3个css文件:
其实三个样式都是在header中可以自定义引入

layout.css
template中层位置的定义,完全自己定义,可把自己写的css样式放在里面

style.css
每一块的样式,可修改内容,不要改id

modules.css
模组的显示样式

样式内容虽然看起来很多,但其实只要找到正确的id,需要的改的地方并不多。

相关问题可以参考:
Templates and Template Engines
Open discussion on Drupal's themeing capabilities and templating engines

简单介绍了一下自己改 Drupal 模板的经验,希望大家能改出更好看的template。