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

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,微信登陆

搜索

[Drupal教程] Drupal:定制维护页面HTML

[复制链接]
发表于 3-13-2012 18:16 | 显示全部楼层 |阅读模式

原文地址:http://drupal.org/node/1209088

译者:这个文档描述的Drupal 6.x的维护页面定制方法。对D7应该也有一定的参考意义。
虽然是Drupal 6.x的文章,但觉得这篇文章有点Drupal way的意思,所以强自翻译,请指正。

原文如下:

当网站处于维护模式下时,我们期望不管用户输入本网站url是什么,都会被引导到一
个维护界面上。在Drupal 6.x中,我们可以通过如下方法做到这一点。

  • 方法一
  • 在"root/themes/garland/page.tpl.php"或默认维护主题的page.tpl.php中定义site-offline.html:(译者:在同一目录的template.php定义更合适一些,它会覆盖系统默认函数)

    function phptemplate_maintenance_page($content, $messages = TRUE, $partial = FALSE) {
    5 s7 w3 n3 @- R! B  drupal_goto('path/to/your/site-offline.html');1 }; M1 r( O9 ^+ B$ l9 r8 V7 ?5 e
    }# j0 ^0 T& d2 ?
    

    这种方法来源于http://blah.com/offline.html,它的缺点是不允许用户刷新页面。

  • 方法二
  • 在脱机维护时,你想使用定制的主题作为脱机维护页面,但系统不允许你使用。这时,你需要修改位于“root/sites/default”的settings.php的文件权限,增加读,写,执行权限。然后,取消以下三行代码的注释状态,并将维护主题从"garland"修改为你希望的主题,比如是minnelli。

    修改前:

    1) #   $conf = array(
    . b/ S. k( X1 I0 r! V5 m2) #   'maintenance_theme' => 'minnelli',5 O; k# I. P/ S8 t: V- N# R! w5 G6 u
    3) #   );, A( J- N* v. a/ t+ O- Y# C% Q
    

    修改后:

    1)     $conf = array(6 t' }. W, C& C: S1 D% C) _/ [
    2)     'maintenance_theme' => 'minnelli',* v) L& b  ~$ k! R& `2 w
    3)     );1 b3 a+ l- G2 P1 q: ~$ n
    

    这将让你得到你期望的维护主题,但它与一些主题匹配得并不好,而且缺乏灵活的.css或者HTML内容。

  • 方法三
  • 这将允许您完全定制HTML页面作为脱机维护页面,不需要file.html的扩展,它仍然在以前的页面上。按照方法二的指示进行设置,除了主题部分,也不包括maintenance-page.tpl.php 和 maintenance-page-offline.tpl.php的内容。在设置了settings.php后,复制两份page.tpl.php,分别命名为"maintenance-page.tpl.php" 和"maintenance-page-offline.tpl.php"。删除这两个文件的全部内容,并创建如下几行:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" lang="<?php print $language->language ?>" xml:lang="<?php print $language->language ?>">

    <?php
    $head_title = 'Site Offline';
    $content =
    ?>

    <head>
    <title><?php print $head_title ?></title>
    <?php print $content ?>
    <!--[if lt IE 7]>
    <style type="text/css" media="all">@import "<?php print base_path() . path_to_theme() ?>/fix-ie.css";</style>
    <![endif]-->
    <script type="text/javascript"><?php /* Needed to avoid Flash of Unstyle Content in IE */ ?></script>
    </head>

    <?php
    $theme_width = "width";
    $theme_width = theme_validate_page_width($theme_width);
    ?>
    </html> ( v# u7 T8 d; Q9 r+ {

    注:确保在php部分的底部,使用你期望的主题宽度函数替换掉theme_validate_page_width($theme_width)。

    接下来,按照你的想法,生成.html和.css配置文件,例如:

    <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN' 'http://www.w3.org/TR/html4/loose.dtd'>
    <html lang='en-US'><head><title>site is Offline</title>
    <link rel='alternate' type='application/rss+xml' title='site.com' href='http://site.com/feeds/general'>
    <link rel='SHORTCUT ICON' href='sites/default/files/favicon.ico'>
    <style>body {
    font-family: Verdana,Arial,Helvetica,sans-serif;
    font-size: 76%;
    color: #000;
    margin: 20px;
    background: #292929;
    text-align: center;
    }
    a
    {
    color: #EFEFEF;
    font-weight: bold;
    }
    a:link {
    }
    a:visited {
    }
    a:active {
    }
    h2 {
    font-size: 1.5em;
    border-bottom: 1px solid silver;
    padding-bottom: 3px;
    clear: both;
    }
    pre {
    max-height: 240px.........
    </style></head>' }+ Q* B8 Q- `& a* ^

    如下是网页的.css配置,最后把你的HTML完成。

    </head>
    <body>
    <div class='logo'><a href='http://site.com'><img src='sites/default/files/sitelogo.png'
    <div class='content'>
    </div>
    <div class='footer'>
    </div>
    </body>
    </html># c9 |8 j: n, U9 N0 r

    一旦你准备好“site is offline page”和“site maintenance page”的html内容后,用"替换所有的',并用'括起来,当然也可以采用其他方式。如果是html中必须有的'和"可以用'和"替代。当这些都对齐之后,把文件内容粘贴到‘$content =’之后,注意,'='之后要有一个空格,并在html之后增加‘;’。

    感谢你读这篇教程,我希望这对你有用。 :)


感谢 nerochen !




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

GMT+8, 2-19-2025 13:50 , Processed in 0.302849 second(s), 62 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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