• 首页
  • 搜索
  • 夜间模式
    ©2012-2025  Feng's Blog Theme by OneBlog
    搜索
    标签
    # 随笔 # 维修 # Wordpress # 阿里云 # 服务器 # typecho # Ghost # iphone # 网站 # word
  • 首页>
  • IT网络>
  • 正文
  • 给Wordpress评论者信息栏加入新浪微博账号输入框

    2016年10月30日 68 阅读 0 评论 1927 字

    首先就是无论你采用哪种方法,都要在 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='<a href="http://weibo.com/n/$tw">http://weibo.com/n/$tw</a>' title='@$tw' target='_blank'>@$tw</a>";
    return $author;
    }

    如果是自定义评论,则在 comments.php 相应位置:

    如果是默认的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;
    }
    本文著作权归作者 [ Feng ] 享有,未经作者书面授权,禁止转载,封面图片来源于 [ 互联网 ] ,本文仅供个人学习、研究和欣赏使用。如有异议,请联系博主及时处理。
    Wordpress
    — END —
    首页
    Copyright©2012-2025  All Rights Reserved.  Load:0.015 s
    Theme by OneBlog V3.6.3
    夜间模式

    开源不易,请尊重作者版权,保留基本的版权信息。