有时候,博客首页需要增加新的页面,一旦点击页面就可以直接跳转到自己希望转向的BBS或者其他自己想要的站点。

为此,需要在Wordpress现有主题下,添加新的页面模板。每个Wordpress主题都有默认的主题模板,但也可以在该主题下定制自己的页面模板。现在我在使用的主题目录下,新建文件redirect.php,然后在文件中添加如下内容:

/*Template Name: Redirect*/if (have_posts()) {the_post();$pattern = '@(https?://([-w.]+)+(:d+)?(/([w/_.]*(?S+)?)?)?)@';preg_match($pattern, get_the_excerpt(), $matches);if ($matches[0]) header('Location: '.$matches[0]);else echo 'Enter a URL into your page body text.';}?>

保存该文件。然后到Wordpress后台——》页面,添加新页面,在页面内容中添加你要连接到的页面地址.然后再编辑页面的右下角,选择页面模板为“Redirect”,并保存页面即可。