文档说明:
我们都知道,Nginx/Apache等都可以将网站的404错误页进行重定向到指定的页面,事实上,Typecho的路由便可以不借助这点来更快实现。
涉及文件:
usr/themes/当前正在使用的模版/404.php
使用说明:
1.在当前使用的Typecho模版目录下新建一个404.php文件(若无)
2.编辑404.php文件内容如下:
<?php if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?>
<?php $this->need('header.php'); ?>
<div class="col-mb-12 col-tb-8 col-tb-offset-2">
<div class="error-page">
<h2 class="post-title">404 - <?php _e('页面没找到'); ?></h2>
<p><?php _e('你想查看的页面已被转移或删除了, 要不要搜索看看: '); ?></p>
<form method="post">
<p><input type="text" name="s" class="text" autofocus/></p>
<p>
<button type="submit" class="submit"><?php _e('搜索'); ?></button>
</p>
</form>
</div>
</div>
<?php $this->need('footer.php'); ?>
说明:
你也可以直接将typecho默认模板目录下的404.php文件拷贝一份至当前模板目录下。
通过这种方式创建的404页面可以通过引入全局文件从而直接使用widget方式获取网站内容来丰富404页面。