修改版WordPress跳转页

ė 1,902 6 2
本文最近更新于17.02.23 周四请自行判断新内容

发现像张戈的WordPress跳转页做得太过复杂了,而且还要设置伪静态。当然你也不用设置,为止他写了两篇文章来介绍如何实现这个功能。目前我一介小民网取消了内容中外链跳转功能,因为出现弹窗视频中有跳转页导致无法播放视频的问题。
当然不是用知更鸟ality/Begin主题和古今Tree/Nana主题的用户可以做文章内容跳转。以下代码请放在functions.php模版函数文件内,文章内容跳转代码:

第一步

首先新建一个跳转页模版放在主题文件内,之后需新建页面,模板选择Go跳转页面,别名为go。跳转页模版代码:▼展开可见

<?php
/*
Template Name:外链跳转
*/

if(strlen($_SERVER['REQUEST_URI']) > 384 ||
strpos($_SERVER['REQUEST_URI'], "eval(") ||
strpos($_SERVER['REQUEST_URI'], "base64")) {
@header("HTTP/1.1 414 Request-URI Too Long");
@header("Status: 414 Request-URI Too Long");
@header("Connection: Close");
@exit;
}
//通过QUERY_STRING取得完整的传入数据,然后取得url=之后的所有值,兼容性更好
$t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]);
//数据处理
if(!empty($t_url)) {
//判断取值是否加密
if ($t_url == base64_encode(base64_decode($t_url))) {
$t_url = base64_decode($t_url);
}
//对取值进行网址校验和判断
preg_match('/^(http|https|thunder|qqdl|ed2k|Flashget|qbrowser):\/\//i',$t_url,$matches);
if($matches){
$url=$t_url;
$title='页面加载中,请稍候...';
} else {
preg_match('/\./i',$t_url,$matche);
if($matche){
$url='http://'.$t_url;
$title='一介小民提示示:页面加载中,请稍候...';
} else {
$url='' . home_url() . '';
$title='参数错误,正在返回首页...';
}
}
} else {
$title='参数缺失,正在返回首页...';
$url='' . home_url() . '';
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="robots" content="noindex, nofollow" />
<meta http-equiv="refresh" content="3;url='<?php echo $url;?>';">
<title><?php echo $title;?></title>
<style>body{background:#000}.loading{-webkit-animation:fadein 2s;-moz-animation:fadein 2s;-o-animation:fadein 2s;animation:fadein 2s}@-moz-keyframes fadein{from{opacity:0}to{opacity:1}}@-webkit-keyframes fadein{from{opacity:0}to{opacity:1}}@-o-keyframes fadein{from{opacity:0}to{opacity:1}}@keyframes fadein{from{opacity:0}to{opacity:1}}.spinner-wrapper{position:absolute;top:0;left:0;z-index:300;height:100%;min-width:100%;min-height:100%;background:rgba(255,255,255,0.93)}.spinner-text{position:absolute;top:50%;left:50%;margin-left:-90px;margin-top: 2px;color:#211e1e;letter-spacing:1px;font-weight:600;font-size:30px;font-family:Arial}.spinner{position:absolute;top:50%;left:50%;display:block;margin-left:-160px;width:1px;height:1px;border:25px solid rgba(255,0,0,1);-webkit-border-radius:50px;-moz-border-radius:50px;border-radius:50px;border-left-color:transparent;border-right-color:transparent;-webkit-animation:spin 1.5s infinite;-moz-animation:spin 1.5s infinite;animation:spin 1.5s infinite}@-webkit-keyframes spin{0%,100%{-webkit-transform:rotate(0deg) scale(1)}50%{-webkit-transform:rotate(720deg) scale(0.6)}}@-moz-keyframes spin{0%,100%{-moz-transform:rotate(0deg) scale(1)}50%{-moz-transform:rotate(720deg) scale(0.6)}}@-o-keyframes spin{0%,100%{-o-transform:rotate(0deg) scale(1)}50%{-o-transform:rotate(720deg) scale(0.6)}}@keyframes spin{0%,100%{transform:rotate(0deg) scale(1)}50%{transform:rotate(720deg) scale(0.6)}}</style>
</head>
<body>
<div class="loading">
<div class="spinner-wrapper">
<span class="spinner-text">页面加载中,请稍候...记得回来哦?</span>
<span class="spinner"></span>
</div>
</div>
</body>
</html>

第二步在模版函数文件functions.php内加入跳转代码。

我的主题设置中增加了是否打开跳转选项,这样就方便多了。

if(get_option('ygj_wlgonof'))://判断是否开否跳转,当然如果你主题设置中没有这个选项可以删除或者增加。
add_filter('the_content','the_content_nofollow',999);

function the_content_nofollow($content)

{

preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);

if($matches && !is_page('about')){

foreach($matches[2] as $val){

if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){

$content=str_replace("href=\"$val\"", "href=\"".home_url()."/go/?url=".base64_encode($val)."\" target=\"_blank\" rel=\"nofollow\" ",$content);

}

}

}

return $content;

}

endif;//判断结束,没有的可以删除。

评论跳转没有做是否开启外链跳转判断,完全没有必要。代码:

// 评论用户外链跳转代码

function commentauthor($comment_ID = 0) {

$url = get_comment_author_url( $comment_ID );

$author = get_comment_author( $comment_ID );

if ( empty( $url ) || 'http://' == $url )

echo $author;

else

echo "<a href='".home_url()."/go/?url=".base64_encode($url)."' rel='nofollow' target='_blank' class='url'>$author</a>";

}

其实没做什么修改,只是综合了他的两篇文章分别做了64位加密网址与给主题设置是否开启跳转选项及一些小细节更改,对了我取消了伪静态跳转设置,给跳转加了target='-blank'新窗口打开。你会了吗?我使用的是Tree主题,想要就点击

  • 灵魂发问:谁告诉你我国防空洞位置了吗?怕是99%中国人不知道,我也不知道,为什么,因为没告诉咱们啊!怕是很多当官的都不晓得吧!所以别老想着打这个那个,真打起来,你躲都不知道躲哪?最好的位置是到没有军事区,机场等落后位置,因为人家炸这些位置不仅没有利益还会被国际谴责。 --- 2025/03/08
主机推荐
留言区 (1,902阅已有 2 条留言,我也要留言
:网友留言区仅供网友表达其个人观点,并不表明栖息邦最终立场。



  1. 1F

    挺给力的跳转~虽然是EM,不过也移植了你们的这个。

    2017年1月13日 15:06 回复
    1. 2F
      如风 小白来自天朝的朋友 谷歌浏览器 Windows 7

      @姜辰取消了内容外链中转

      2017年1月13日 18:00 回复
管理员登录
注册

提示:点击上下面区域关闭

字号调整

View My Stats
空位 空位
本次加载耗时:0.395s