Typecho评论链接重定向的实现

时间:2020-08-01   阅读:367

Typecho评论链接重定向的实现


wordpress有这种评论链接跳转,在Typecho大牛的努力下。Typecho也有评论链接跳转代码了。
效果图:
 Typecho评论链接重定向的实现 文章

首先打开var/Widget/Abstract/Comments.php文件,寻找

if ($this->url && $autoLink) {    
            echo '<a href="' , $this-&gt;url , '"' , ($noFollow ? ' rel="external nofollow"' : NULL) , '>' , $this->author , '</a>';    
        } else {    
            echo $this->author;    
        }


修改为

if ($this-&gt;url && $autoLink) {    
            if(strpos($this-&gt;url, $this->options->siteUrl)!==false) {    
                echo '<a href="', $this-&gt;url, '"&gt;', $this->author, '</a>';    
            } else {    
                echo '<a href="', $this-&gt;options-&gt;siteUrl, 'go.html?url=', urlencode($this->url), '"', ' rel="nofollow"', '>', $this->author, '</a>';    
            }    
        } else {    
            echo $this->author;    
        }


跳转页采用的是html静态页+javescript方式跳转,你也可以改用php方式,我的跳转go.html代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">    
<html xmlns="http://www.w3.org/1999/xhtml">    
<head profile="http://gmpg.org/xfn/11">    
 <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />    
 <title>Microhu's Blog - 正常跳转</title>    
 <style type="text/css">    
    #show{width:500px;margin:100px auto 0;font-size:18px;color:blue;}    
    #show span{color:red;font-weight:blod;}    
 </style>    
</head>    
<body>    
<div id="show"></div>    
 <script type="text/javascript">    
 <!--    
    function getUrl(){    
        var theUrl=location.href.split('?url=');    
        if(theUrl.length==1)    
            return 'http://www.microhu.com';    
        return decodeURIComponent(theUrl[1]);    
    }    
    var showme=document.getElementById('show');    
    showme.innerHTML='正在为你跳转到:<span>'+getUrl()+'</span>';    
    location=getUrl();    
 //-->    
 </script>    
</body>    
</html>


方法来自:@羊窝 http://www.yangwo.net/170/


上一篇:Typecho评论输出调用代码

下一篇:Typecho 首页第一篇文章显示不一样

网友评论