2010-04-30 61 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數據庫空數據庫字段的值你想