首先就是无论你采用哪种方法,都要在functions.php
中加入如下代码:
add_action( 'comment_post','save_comment_meta_data' );
function save_comment_meta_data( $comment_id ) {
add_comment_meta( $comment_id, 'sinawb', $_POST['sinawb'] );
$expire = time() + 99999999;
$domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; // make cookies work with localhost
setcookie('bigfa_sinawb',$_POST['sinawb'],$expire,'/',$domain,false);
}
add_filter( 'get_comment_author_link', 'attach_twitter_to_author' );
function attach_twitter_to_author( $author ) {
$tw = get_comment_meta( get_comment_ID(), 'sinawb', true );
if($tw)
$author .= " / <a href='http://weibo.com/n/$tw' title='@$tw' target='_blank'>@$tw</a>";
return $author;
}
如果是自定义评论,则在comments.php
相应位置:
<label id="author_sinawb" for="sinawb">Weibo.<input id="sinawb" type="text" tabindex="5" value="<?php if(isset($_COOKIE['bigfa_sinawb'])) echo $_COOKIE['bigfa_sinawb'];?>" name="sinawb">
</label>
如果是默认的comment_form,则下面的代码加到functions.php
中:
add_filter( 'comment_form_defaults', 'change_comment_form_defaults');
function change_comment_form_defaults($default) {
$commenter = wp_get_current_commenter();
$default['fields']['url'] .= '<p class="comment-form-author"><label id="author_sinawb" for="sinawb">Weibo<input id="sinawb" type="text" tabindex="5" value="';
if(isset($_COOKIE['bigfa_sinawb'])) $default['fields']['url'] .= $_COOKIE['bigfa_sinawb'];
$default['fields']['url'] .='" name="sinawb"></label></p>';
return $default;
}
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可