iNove主题 评论者网址链接 在新窗口打开并重定向跳转
话说大亨MG12的 iNove主题享誉同际,可两个经历使我比较纠结……
经历一:评论者网址新窗口打开
在宋夏那看到wordpress评论者网址链接在新窗口打开方法:
1、打开 wp-includes/comment-template.php
2、查找 function get_comment_author_link
3、在适当位置添加见下图:target='_blank' (引号是英文半角的,千万别写错呦)
iNove照此方法无效!
经历二:评论网址重定向跳转
在万戈那看到WordPress评论链接重定向跳转方法
iNove照方法将代码丢进Functions.php无效!
今天终于找到了解决方法。
iNove评论者网址新窗口打开
并不是修改wp-includes/comment-template.php,而是修改主题下functions.php 找到
<div class="name">
<?php if (get_comment_author_url()) : ?>
<a id="commentauthor-<?php comment_ID() ?>" class="url" href="<?php comment_author_url() ?>" rel="external nofollow">
修改为
<div class="name">
<?php if (get_comment_author_url()) : ?>
<a target="_blank" id="commentauthor-<?php comment_ID() ?>" class="url" href="<?php comment_author_url() ?>" rel="external nofollow">
这样评论链接就在新窗口打开了!
iNove评论者网址重定向跳转
1.将以下代码加入到iNove主题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').'/?to=', $text);
$text=str_replace("href='", "href='".get_option('home')."/?to=", $text);
return $text;
}
add_action('init', 'redirect_comment_link');
function redirect_comment_link(){
$redirect = $_GET['to'];
if($redirect){
if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){
header("Location: $redirect");
exit;
}
else {
header("Location: http://surda.cn/"); //修改为自已的wp网址
exit;
}
}
}
?>
/*--注明:你可能看到第三行注释掉的代码,这是取消评论内容里的链接重定向跳转.目的是避免"@user"链接显示错误,懒的修改comment.js –*/
2.仍然是在主题functions.php找到刚刚修改的
<div class="name">
<?php if (get_comment_author_url()) : ?>
<a target="_blank" id="commentauthor-<?php comment_ID() ?>" class="url" href="<?php comment_author_url() ?>" rel="external nofollow">
修改为
<div class="name">
<?php if (get_comment_author_url()) : ?>
<a target="_blank" id="commentauthor-<?php comment_ID() ?>" class="url" href="<?php echo get_settings('home'); ?>/?to=<?php comment_author_url() ?>">
OK,这样评论作者网址就重定向跳转打开了.
/*--因为已经应用了重定向 rel="external nofollow" 属性就去除了,
另:据说http://surda.cn/?to=http://www.google.com这种形式对爬虫不是太友好!故请往下看—*/
3.在Robots.txt加入
Disallow: /?to=*
限制机器人抓取这个重定向链接.
--------------------------------------------周末分割线------------------------------------------------------------
但SurDA也不建议采用这种形式跳转。add_action('init', 'redirect_comment_link');
//这种方式全局加载init,无形中增加了index.php负担,相当于把处理链接跳转任务都丢给index.php,一般建议新建一个文件专门处理跳转任务,往下看……
说说SurDA目前使用的跳转方法 – php跳转法(iNove主题)
1.新建to.php放置博客根目录,代码如下:
<?php header("location:".$_GET["url"]); ?>
2.将iNove主题functions.php代码
<div class="name">
<?php if (get_comment_author_url()) : ?>
<a target="_blank" id="commentauthor-<?php comment_ID() ?>" class="url" href="<?php echo get_settings('home'); ?>/?to=<?php comment_author_url() ?>">
修改为
<div class="name">
<?php if (get_comment_author_url()) : ?>
<a target="_blank" id="commentauthor-<?php comment_ID() ?>" class="url" href="<?php echo get_settings('home'); ?>/to.php?url=<?php comment_author_url() ?>">
3.如果也不想爬虫抓取,在Robots.txt加入
Disallow: /to.php?url=*
看看我评论里的效果吧……

![酷歪人主机,优惠码[surda.cn]](http://img.surda.cn/ads/yculer.jpg)

我基本都是用插件来实现这些功能
@Firm
不能太相信插件,昨天才刚刚反安装WP-SUPER-CACHE插件.
我用的是jQ跳转 呵呵
呵呵,我觉得没必要改这个吧?
如果点评论者的链接就是想看评论者的博客嘛。
干嘛还要重定向到你自己的呢?
不大理解哈。。
@david
哥们 误会了 不是重定向到自已的网站 只是通过一过渡平台到访客网站
修改代码还是要有一定程度上对代码的熟悉程度才行
相比之下偶觉得iNove的代码可读性算是比较好的了wwwwwwwww修改的时候只要大致对HTML或者JS什么的有个大致的了解(或者英语比较好)的话还是比较容易找到位置的
target="_blank"是链接代码(<a xxxxxx>代码)的Attribute,所以只要知道这一点,再找到生成评论者链接的代码,就可以很轻松地找对修改的位置了
很早之前添加了。用的是类似荒野无灯的方法,本质上应该和你这个差不多。
新窗口打开那个,我的function里有这么一句<?php printf(__('%s'), get_comment_author_link()) ?>,请问应该把target='_blank' 加在哪里啊?
@有点蓝
你的主题与我的不一样 你应该修改 wp-includes/comment-template.php 相应位置 详见文章开头
看看!
测试测试@!
兄弟,我找了一下午,只有你这个方法好使呀,其他的都不行,谢谢您
试一下,我都打算用这主题。
完全按最后的方法,只能跳到一个404.不知为什么、
@探索者
可能是 URL设置有误
那里的URL设置有误?我检查过和这个一样修改了,不知是那里出问题
按上面提到的代码放进去。再按最后的方法才行。
分页的问题不知道怎么搞
找了N圈,还是在你这里找到了答案,哈哈。谢谢了啊!!!!!