步骤一
在当前主题的根目录下新建一个页面模板php文件,可以命名为link.php,并加入下边的代码:
<?php /* Template Name: 外链跳转 */ $transition = get_post_meta($post->ID,"transition", $single=true); $false='false'; if ($transition==$false){ $url = $_GET['url']; Header("Location:$url"); } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <?php $time=get_post_meta($post->ID,"time", $single=true); ?> <meta http-equiv="refresh" content="<?php echo $time ;?>;url='<?php echo $_GET['url'];; ?>';"> <title>页面跳转|<?php bloginfo('name'); ?></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:41.5%;left:47%;margin:16px 0 0 35px;color:#BBB;letter-spacing:1px;font-weight:700;font-size:9px;font-family:Arial}.spinner{position:absolute;top:40%;left:45%;display:block;margin:0;width:1px;height:1px;border:25px solid rgba(100,100,100,0.2);-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">LOADING...</span> <span class="spinner"></span> </div> </div> </body> </html>
上面的代码定义了几个东西:1、自定义字段transition和time,transition是是否要显示过渡(可选,设置false则不显示)、time是在过渡页面停留的时间(必须,单位为秒,可设置3~5秒);2、过渡动画,见CSS。
步骤二
到WP后台——新建页面——固定链接填写为link,填写自定义字段time和它的值,没有就添加自定义栏目,选择刚才新建的link.php模板,保存!如下图:
这样我们就有了一个跳转页面—— http://127.0.0.1/link
跳转的链接方式为——http://127.0.0.1/link?url=http://www.inlojv.com
这个可以手动加在评论者的链接前面,也可以用下面的代码放进functions.php里面进行统一修改:
<?php //评论者链接重定向 add_filter('get_comment_author_link', 'add_redirect_comment_link', 5); add_filter('comment_text', 'add_redirect_comment_link', 99); function add_redirect_comment_link($text = ''){ $text=str_replace('href="', 'href="'.get_option('home').'/link?url=', $text); $text=str_replace("href='", "href='".get_option('home')."/link?url=", $text); return $text; } add_action('init', 'redirect_comment_link'); function redirect_comment_link(){ $redirect = $_GET['r']; $redirect = trim(str_replace("\r","",str_replace("\r\n","",strip_tags(str_replace("'","",str_replace("\n", "", str_replace(" ","",str_replace("\t","",trim($redirect))))),"")))); $host = $_SERVER['HTTP_HOST']; if($redirect){ if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){ header("Location: $redirect#form:$host"); exit; } else { header("Location: $redirect#form:$host"); exit; } } } ?>
以上。
本站文章除注明转载/出处外,均为本站原创或翻译。若要转载但请务必注明出处,尊重他人劳动成果。
转载请注明出处链接 : https://www.inlojv.com/4252.html