2010-04-30 60 views
1

在WordPress的形式,当你留下评论作为嘉宾,有一个网站字段填写您的网址。如果我们认真填写框,我们可以通过调用这个函数评论作者链接WordPress的

<?php echo get_comment_author_link(); ?> 

获得链接,但如果你登录,你不要在你的个人资料添加网站,当你离开评论。它没有你的用户名的链接。

我要的是,如果登录的用户没有网站,将有将被随身携带他们的个人资料页面的链接是像http://www.example.com?author=21

有什么功能我可以在那里使用?请帮助我。谢谢。

回答

6

放弃这一在主题functions.php;

function force_comment_author_url($comment) 
{ 
    // does the comment have a valid author URL? 
    $no_url = !$comment->comment_author_url || $comment->comment_author_url == 'http://'; 

    if ($comment->user_id && $no_url) { 
     // comment was written by a registered user but with no author URL 
     $comment->comment_author_url = 'http://www.example.com/?author=' . $comment->user_id; 
    } 
    return $comment; 
} 
add_filter('get_comment', 'force_comment_author_url'); 
+0

感谢作品像一个魅力。我真的想给你投票。目前我没有足够的代表投票。再次感谢你。 – knightrider 2010-05-01 02:23:50

+0

没问题,很高兴帮助:) – TheDeadMedic 2010-05-01 16:05:25

-1

嗯,我想一个解决办法是有一个PHP/MySQL的脚本更新WordPress数据库空数据库字段的值你想