欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

定制维护页面HTML

译者:这个文档描述的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定义更合适一些,它会覆盖系统默认函数)

?

123function phptemplate_maintenance_page($content, $messages = TRUE, $partial = FALSE) {  drupal_goto('path/to/your/site-offline.html');}

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

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

修改前:

?

123#   $conf = array(#   'maintenance_theme' => 'minnelli',#   );

修改后:

?

123$conf = array(    'maintenance_theme' => 'minnelli',);

这将让你得到你期望的维护主题,但它与一些主题匹配得并不好,而且缺乏灵活的.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>

注:确保在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> 如下是网页的.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>

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

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


来自  http://drupalchina.cn/page/886.html

普通分类: