WordPress插件制作笔记(三)---Stars Comments Article

 wp 文章星级评价 插件

下载地址4:http://pan.baidu.com/s/1eQnGIGU [articles_star_vote_score_optiontable_serialize_commentvote.zip]*推荐 最新

1.自定义表与 wp_options 表

2.修改插入数据库配置项,为serialize序列化的value值,在wp的options表中存储

3.增加暂停插件选项,增加comment评论时的打分,可以自定义开始 文章打分,评论时打分,或是暂停使用打分

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

下载地址3:http://pan.baidu.com/s/1qWrzZnY [articles_star_vote_score_optiontable_serialize.zip]*推荐

1.修改表为自定义创建数据库表与 wp_options表结合,插入serialize序列化的value值

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

下载地址2:http://pan.baidu.com/s/1o6skeIe  [articles_star_vote_score_optionstable.zip]

1.修改使用wp register_setting(‘group’) 插入wp_options 表多个键的存储方式

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

下载地址1:http://pan.baidu.com/s/1qWAwQPu   [articles_star_vote_score.zip]*推荐 (自定义数据库表)

1.使用2张自定义表存储数据

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

 

 

 

Readme.text

// directory:



// wordpress/wp-content/plugins/articles_star_vote_score



// articles_star_vote_score

//   |--assets

//     |--css

//       |--style.css

//     |--img

//       |--star.jpg

//     |--js

//       |--jquery-1.10.2.js

//       |--show_star.js

//   |--Readme.text

//   |--stars_vote_score.php

//   |--stars_vote_settings.php

//   |--stars_vote_update.php

 

stars_vote_score.php 

<?php

/*

  Plugin Name: Articles Star Vote Score

  Plugin URI: http://www.cnblogs.com/fxmbz/p/4057971.html

  Description: Vote score for each article. <strong>Warning: Deactivate the plugin will delete all ovte data !</strong>

  Version: 1.0

  Author: Zhangxl

  Author URI: http://www.cnblogs.com/fxmbz/

 */



/*

  Copyright 2014  Zhangxl  (email : [email protected])



  This program is free software; you can redistribute it and/or modify

  it under the terms of the GNU General Public License as published by

  the Free Software Foundation; either version 2 of the License, or

  (at your option) any later version.



  This program is distributed in the hope that it will be useful,

  but WITHOUT ANY WARRANTY; without even the implied warranty of

  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the

  GNU General Public License for more details.



  You should have received a copy of the GNU General Public License

  along with this program; if not, write to the Free Software

  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

 */



// if not add_action then warning and exit;

if (!function_exists('add_action')) {

    echo 'Hi there!  I\'m just a plugin, not much I can do when cwholeed directly.';

    exit;

}



// Define constants plugins version, run minimum wp version, plugins URL, plugins DIR

define('STARVOTE_VERSION_NUM', '1.0');

define('STARVOTE__MINIMUM_WP_VERSION', '4.0');

define('STARVOTE__PLUGIN_URL', plugin_dir_url(__FILE__));

define('STARVOTE__PLUGIN_DIR', plugin_dir_path(__FILE__));



// Define global variable $wpdb, data table

global $wpdb;

define('STARVOTE_LOG_TABLE', $wpdb->prefix . 'starvote_log');

define('STARVOTE_CONFIG_TABLE', $wpdb->prefix . 'starvote_config');



// Activation plugins call function 

register_activation_hook(__FILE__, 'starvote_install');

register_activation_hook(__FILE__, 'starvote_install_data');



// Load stars_settings_page.php

require_once(STARVOTE__PLUGIN_DIR . 'stars_vote_settings.php');



// Deactivation plugins run function

register_deactivation_hook( __FILE__, 'starvote_deactivation');



// Add the hooks function, when loading the plug-in run function

add_action('plugins_loaded', 'starvote_update_db_check');



// Add the hooks function, when init run function

add_action('init', 'initialize_hooks');



/**

 * initialize_hooks when add_action init call function

 */

function initialize_hooks() {

    // when loading the wp_head call function

    add_action('wp_head', 'load_script');

    // when loading the the_content call function

    add_filter('the_content', 'display_stars');

    if (is_admin()) {

        add_action('admin_menu', 'add_settings_pages');

    }

}



/**

 * starvote_deactivation when deactivation plugin drop table

 */

function starvote_deactivation() {

    global $wpdb;

    $wpdb->query("DROP TABLE IF EXISTS " . STARVOTE_LOG_TABLE);

    $wpdb->query("DROP TABLE IF EXISTS " . STARVOTE_CONFIG_TABLE);

    delete_option('starvote_version_num', STARVOTE_VERSION_NUM);

}



/**

 * starvote_install when activation plugin create table, update options table starvote_version_num field

 */

function starvote_install() {

    global $wpdb;



    $charset_collate = '';



    if (!empty($wpdb->charset)) {

        $charset_collate = "DEFAULT CHARACTER SET " . $wpdb->charset;

    }



    if (!empty($wpdb->collate)) {

        $charset_collate .= "COLLATE " . $wpdb->charset;

    }



    $create_starvote_log = "CREATE TABLE " . STARVOTE_LOG_TABLE . " (

        id integer NOT NULL AUTO_INCREMENT,

        post_id integer NOT NULL,

        user_id integer NOT NULL,

        sum_votes decimal(10,1) NOT NULL,

        ip varchar(45) NOT NULL,

        time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

        PRIMARY KEY (id)

    ) $charset_collate;";



    $create_starvote_config = "CREATE TABLE " . STARVOTE_CONFIG_TABLE . " (

        id integer NOT NULL AUTO_INCREMENT,

        star_style tinyint NOT NULL DEFAULT 0 COMMENT '0 small, 1 big',

        star_counts tinyint NOT NULL DEFAULT 0 COMMENT '0 5star, 1 10star',

        star_position tinyint NOT NULL DEFAULT 0 COMMENT '0 after 1 before',

        show_statistics tinyint NOT NULL DEFAULT 1 COMMENT '0 none, 1 show',

        show_statistics_type tinyint NOT NULL DEFAULT 0 COMMENT '0 number, 1 percentage',

        vote_permissions tinyint NOT NULL DEFAULT 1 COMMENT '0 none, 1 ip limit, 2 ip and login limit',

        PRIMARY KEY (id)

    ) $charset_collate;";



    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );

    dbDelta($create_starvote_log);

    dbDelta($create_starvote_config);



    update_option('starvote_version_num', STARVOTE_VERSION_NUM);

}



/**

 * load_script loading js and css

 */

function load_script() {

    if (!is_single()) {

        return;

    }

    wp_enqueue_script('jquery-js', STARVOTE__PLUGIN_URL . 'assets/js/jquery-1.10.2.js');

    wp_enqueue_script('star-js', STARVOTE__PLUGIN_URL . 'assets/js/show_star.js');

    _e('<link type="text/css" rel="stylesheet" href="' . STARVOTE__PLUGIN_URL . 'assets/css/style.css" />');

}



/**

 * display_stars display if not sigle page return then return vote statistics info

 * @param  string The current article content

 * @return string content and vote statistics info

 */

function display_stars($content) {

    global $wpdb;



    if (!is_single()) {

        return $content;

    }

    

    // get when article id;

    $post_id = get_the_ID();

    // call function get starvote_config table info

    $query = get_starvote_config();

    $vote_permissions = $query->vote_permissions; // obtain vote_permissions field value



        // if vote_permissions value = 2 limit to vote after the user login then vote score

    if ($vote_permissions != 2 || get_current_user_id()) {

        $star_position = $query->star_position < 1 ? 0 : 1; //0 content bottom, 1 content top



        if ($star_position < 1) {

            return $content . stars_style($post_id) . '<div id="statistics-container">' . stars_statistics($post_id) . '</div>';

        } else {

            return stars_style($post_id) . '<br />' . $content . '<div id="statistics-container">' . stars_statistics($post_id) . '</div>';

            // return stars_style($post_id) . '<div id="statistics-container">' . stars_statistics($post_id) . '</div>' . $content;

        }

    } else {

        return $content;

    }

}



/**

 * [stars stars show style function ]

 * @param  int The current article id

 * @return string stars style

 */

function stars_style($post_id) {

    global $wpdb;



    $query = get_starvote_config(); 

    $star_style = $query->star_style < 1 ? 0 : 1;

    $star_counts = $query->star_counts < 1 ? 5 : 10;

    $star_position = $query->star_position < 1 ? 0 : 1;

    $show_statistics = $query->show_statistics < 1 ? 0 : 1;

    $show_statistics_type = $query->show_statistics_type < 1 ? 0 : 1;

    $vote_permissions = $query->vote_permissions;



    // The current post_id article all records

    $comment_record_num = $wpdb->query("SELECT sum_votes FROM " . STARVOTE_LOG_TABLE . " WHERE post_id='" . $post_id . "'");



    // sum votes calculate average

    $sum_votes = $wpdb->get_row("SELECT SUM(sum_votes) FROM " . STARVOTE_LOG_TABLE . " WHERE post_id='" . $post_id . "'", ARRAY_A);

    $sum_votes = $sum_votes['SUM(sum_votes)'] ? $sum_votes['SUM(sum_votes)'] / $comment_record_num : 0;



    $starStyle = $star_style ? 'star-big' : 'star-small';

    $star = '<div id="stars"><ul id="' . $starStyle . '">';

    for ($i = 1; $i <= $star_counts; $i++) {

        if ($i < round($sum_votes)) {

            $className = 'whole';

        } else if ($i > round($sum_votes)) {

            $className = 'none';

        } else {

            $className = $sum_votes == round($sum_votes) ? 'whole' : 'half';

        }

        $star .= '<li class="' . $className . '" sum_votes="' . $i . '"></li>';

    }

    $star .= '</ul><div id="avg_score">' . round($sum_votes, 2, PHP_ROUND_HALF_UP) . ' </div><div id="message"></div>';

    $star .= '<input id="ajaxStar" type="hidden" post_id="' . $post_id . '" user_id="' . get_current_user_id() . '" sum_votes="' . $sum_votes . '" value="' . STARVOTE__PLUGIN_URL . 'stars_vote_update.php' . '" /></div>';

    return $star;

}



/**

 * stars vote statistics

 * @param  int The current article id

 * @return string stars statistics info: string

 */

function stars_statistics($post_id) {

    global $wpdb;

    $query = get_starvote_config();

    $star_style = $query->star_style < 1 ? 0 : 1;

    $star_counts = $query->star_counts < 1 ? 5 : 10;

    $star_position = $query->star_position < 1 ? 0 : 1;

    $show_statistics = $query->show_statistics < 1 ? 0 : 1;

    $show_statistics_type = $query->show_statistics_type < 1 ? 0 : 1;

    $vote_permissions = $query->vote_permissions;



    $comment_record_num = $wpdb->query("SELECT sum_votes FROM " . STARVOTE_LOG_TABLE . " WHERE post_id='" . $post_id . "'");



    if ($comment_record_num) {

        $statistics = '<div id="statistics"><span id="ratings-info-position">AVERAGE RATING ( based on <span class="comment_record_num">' . $comment_record_num . '</span> ratings )</span>';

        if ($show_statistics > 0 && $show_statistics_type < 1) {

            for ($i = $star_counts; $i >= 1; $i--) {

                $each_star_counts = $wpdb->query("SELECT sum_votes FROM " . STARVOTE_LOG_TABLE . " WHERE post_id='" . $post_id . "' AND sum_votes={$i} OR post_id='" . $post_id . "' AND sum_votes={$i}-0.5");

                $percentage  = $each_star_counts / $comment_record_num * 100;

                $statistics .= '<div id="counter-container"><span class="counter-label">' . $i . ' Stars</span><span class="counter-back"><span class="counter-bar" style="width: ' . $percentage . '%;"></span></span>' . '<span class="counter-count">' . $each_star_counts . '</span></div>';

            }

        } elseif ($show_statistics > 0 && $show_statistics_type >= 1) {

            for ($i = $star_counts; $i >= 1; $i--) {

                $each_star_counts = $wpdb->query("SELECT sum_votes FROM " . STARVOTE_LOG_TABLE . " WHERE post_id='" . $post_id . "' AND sum_votes={$i} OR post_id='" . $post_id . "' AND sum_votes={$i}-0.5");

                $percentage  = $each_star_counts / $comment_record_num * 100;

                $statistics .= '<div id="counter-container"><span class="counter-label">' . $i . ' Stars</span><span class="counter-back"><span class="counter-bar" style="width: ' . $percentage . '%;"></span></span>' . '<span class="counter-count"> ' . round($percentage, 2, PHP_ROUND_HALF_UP) . ' %</span></div>';

            }

        } else {

            $statistics = '';

        }

    } else {

        if ($show_statistics > 0) {

            $statistics = '<div id="statistics"><span id="ratings-info-position">AVERAGE RATING ( based on <span class="comment_record_num">0</span> ratings )</span>';

            for ($i = $star_counts; $i >= 1; $i--) {

                $statistics .= '<div id="counter-container"><span class="counter-label">' . $i . ' Stars</span><span class="counter-back"><span class="counter-bar" style="width: 0px;"></span></span>' . '<span class="counter-count">0</span></div>';

            }

        } else {

            $statistics = '';

        }

    }

    return $statistics;

}



/**

 * insert default config data

 */

function starvote_install_data() {

    global $wpdb;

    $starvote_config['star_style'] = 1; // 0 small, 1 big

    $starvote_config['star_counts'] = 0; // 0 5star, 1 10star

    $starvote_config['star_position'] = 0; // 0 after 1 before

    $starvote_config['show_statistics'] = 1; // 0 none, 1 show

    $starvote_config['show_statistics_type'] = 1; // 0 number, 1 percentage

    $starvote_config['vote_permissions'] = 1; // 0 none, 1 ip limit, 2 ip and login limit

    $wpdb->insert(STARVOTE_CONFIG_TABLE, $starvote_config);

}



/**

 * get starvote config data

 * @param  string

 * @return obj

 */

function get_starvote_config($field = '*') {

    global $wpdb;

    $query = $wpdb->get_row("SELECT {$field} FROM " . STARVOTE_CONFIG_TABLE);

    if (!$query) {

        starvote_install_data();

    }

    return $query;

}



/**

 * star vote db check and update

 */

function starvote_update_db_check() {

    if (get_option('starvote_version_num') != STARVOTE_VERSION_NUM) {

        starvote_install();

    }

}



/**

 * create admin star vote settings page

 */

function add_settings_pages() {

    add_menu_page('StarVoteSettings', 'StarVoteSettings', 'manage_options', 'star_vote_settings', 'create_settings_pages');

}

 

stars_vote_settings.php

<?php

/**

 * [create_settings_pages create settings page]

 * @return [type] [description]

 */

function create_settings_pages() {

    $query = get_starvote_config();

    ?>

    <div class="wrap">

        <h2>Star Vote Settings</h2>

        <form method="post" action="<?php echo STARVOTE__PLUGIN_URL . 'stars_vote_update.php'; ?>" novalidate="novalidate">

            <table class="form-table">

                <tr>

                    <th scope="row">Star Style</th>

                    <td>

                        <input type="radio" name="star_style" id="" value="0" <?php echo ($query->star_style == 0) ? 'checked="checked"' : ''; ?> />Small &nbsp;

                        <input type="radio" name="star_style" id="" value="1" <?php echo ($query->star_style == 1) ? 'checked="checked"' : ''; ?> />Big

                        <p class="description">Star size, small or big.</p>

                    </td>

                </tr>

                <tr>

                    <th scope="row">Star Counts</th>

                    <td>

                        <input type="radio" name="star_counts" id="" value="0" <?php echo ($query->star_counts == 0) ? 'checked="checked"' : ''; ?> /> 5 Stars &nbsp; 

                        <input type="radio" name="star_counts" id="" value="1" <?php echo ($query->star_counts == 1) ? 'checked="checked"' : ''; ?> /> 10 Stars

                        <p class="description">Star count, 5 or 10.</p>

                    </td>

                </tr>

                <tr>

                    <th scope="row">Sta Position</th>

                    <td>

                        <input type="radio" name="star_position" id="" value="0" <?php echo ($query->star_position == 0) ? 'checked="checked"' : ''; ?> /> bottom &nbsp; 

                        <input type="radio" name="star_position" id="" value="1" <?php echo ($query->star_position == 1) ? 'checked="checked"' : ''; ?> /> top

                        <p class="description">The top or the bottom in the article content.</p>

                    </td>

                </tr>

                <tr>

                    <th scope="row">Show Statistics</th>

                    <td>

                        <input type="radio" name="show_statistics" id="" value="1" <?php echo ($query->show_statistics == 1) ? 'checked="checked"' : ''; ?> /> Show  &nbsp; 

                        <input type="radio" name="show_statistics" id="" value="0" <?php echo ($query->show_statistics == 0) ? 'checked="checked"' : ''; ?> /> None

                        <p class="description">Whether show the Statistics information.</p>

                    </td>

                </tr>

                <tr>

                    <th scope="row">Show Statistics Type</th>

                    <td>

                        <input type="radio" name="show_statistics_type" id="0" value="0" <?php echo ($query->show_statistics_type == 0) ? 'checked="checked"' : ''; ?> /> Counts &nbsp; 

                        <input type="radio" name="show_statistics_type" id="0" value="1" <?php echo ($query->show_statistics_type == 1) ? 'checked="checked"' : ''; ?> /> Percentage

                        <p class="description">The type of the Statistics information.</p>

                    </td>

                </tr>

                <tr>

                    <th scope="row">Vote Permissions</th>

                    <td>

                        <input type="radio" name="vote_permissions" id="vote_permissions" value="1" <?php echo ($query->vote_permissions == 1) ? 'checked="checked"' : ''; ?> /> Ip limit &nbsp; 

                        <input type="radio" name="vote_permissions" id="vote_permissions" value="2" <?php echo ($query->vote_permissions == 2) ? 'checked="checked"' : ''; ?> /> Ip and Login &nbsp; 

                        <input type="radio" name="vote_permissions" id="vote_permissions" value="0" <?php echo ($query->vote_permissions == 0) ? 'checked="checked"' : ''; ?> /> Unlimited (Is not recommended)

                        <p class="description">Vote Permissions.</p>

                    </td>

                </tr>

            </table>

            <input type="hidden" name="id" value="<?php echo $query->id; ?>">

            <input type="hidden" name="update_starvote_config" value="update_starvote_config">

            <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="Save Changes"  /></p>

        </form>

    </div>

    <?php

}

 

stars_vote_update.php

<?php

// Load the corresponding files, judge the REQUEST submitted data, run the corresponding method

if (! isset($wpdb)) {

    global $wpdb;



    define('PATH', dirname(dirname(__FILE__)).'/'); 

    require_once(PATH . '../../wp-blog-header.php');

    require_once('./stars_vote_score.php');

    

    if (isset($_REQUEST['insert_starvote_log'])) {

        insert_starvote_log_data();

    }



    if (isset($_REQUEST['update_starvote_config'])) {

        update_starvote_config_data();

    }

}



/**

 * insert vote data the star vote table

 * @global obj $wpdb

 */

function insert_starvote_log_data() {

    global $wpdb;

    

    $post_id   = $_POST['post_id'];

    $user_id   = $_POST['user_id'];

    $sum_votes = $_POST['sum_votes'];

    $ip        = get_ip();



    $data['post_id'] = $post_id;

    $data['user_id'] = $user_id;

    $data['sum_votes'] = $sum_votes;

    $data['ip'] = $ip;

    

    // vote permissions control

    $vote_permissions = get_starvote_config();

    switch ($vote_permissions->vote_permissions) {

        case 1:

            $query = "SELECT ip, post_id FROM " . STARVOTE_LOG_TABLE . " WHERE post_id = '" . $post_id . "' AND ip='" . $ip . "'";

            if ($wpdb->get_results($query)) {

                echo '<span id="msg">You already commented on, can\'t comment again!</span>' . stars_statistics($post_id);

            } else {

                $wpdb->insert(STARVOTE_LOG_TABLE, $data); 

                echo '<span id="msg">Comments successful!</span>' . stars_statistics($post_id);

            }

            break;



        case 2:

            $query = "SELECT ip, post_id, user_id FROM " . STARVOTE_LOG_TABLE . " WHERE post_id = '" . $post_id . "' AND ip='" . $ip . "' AND user_id='" . $user_id . "'";

            if (get_current_user_id()) {

                if ($wpdb->get_results($query)) {

                    echo '<span id="msg">You already commented on, can\'t comment again!</span>' . stars_statistics($post_id);

                } else {

                    $wpdb->insert(STARVOTE_LOG_TABLE, $data); 

                    echo '<span id="msg">Comments successful!</span>' . stars_statistics($post_id);

                }

            } else {

                echo '<span id="msg">You need to login to comments!</span>' . stars_statistics($post_id);

            }

            break;



        case 0:

            $wpdb->insert(STARVOTE_LOG_TABLE, $data);

            echo '<span id="msg">Comments successful!</span>' . stars_statistics($post_id);

            break;

    }

}





/**

 * update star vote config data table

 * @global obj $wpdb

 */

function update_starvote_config_data() {

    global $wpdb;

    $starvote_config['star_style']           = $_POST['star_style']; // 0 small, 1 big

    $starvote_config['star_counts']          = $_POST['star_counts']; // 0 5star, 1 10star

    $starvote_config['star_position']        = $_POST['star_position']; // 0 after 1 before

    $starvote_config['show_statistics']      = $_POST['show_statistics']; // 0 none, 1 show

    $starvote_config['show_statistics_type'] = $_POST['show_statistics_type']; // 0 number, 1 percentage

    $starvote_config['vote_permissions']     = $_POST['vote_permissions']; // 0 none, 1 ip limit, 2 ip and login limit

    $where['id']                             = $_POST['id'];



    $query = get_starvote_config();

    $star_counts = $query->star_counts;

    

    if ($query) {

        $starvote_data = $wpdb->update(STARVOTE_CONFIG_TABLE, $starvote_config, $where);

    } else {

        $starvote_data = $wpdb->insert(STARVOTE_CONFIG_TABLE, $starvote_config);

    }



    if ($starvote_data) {

        $get_log_table = $wpdb->get_results("SELECT id, sum_votes FROM " . STARVOTE_LOG_TABLE);

        if ($get_log_table) {

            if ($_POST['star_counts'] == 1 && $star_counts != $_POST['star_counts']) {

                foreach ($get_log_table as $v) {

                    $starvote_log_data['sum_votes'] = $v->sum_votes * 2;

                    $where['id'] = $v->id;

                    $wpdb->update(STARVOTE_LOG_TABLE, $starvote_log_data, $where);

                }

            } elseif ($_POST['star_counts'] == 0 && $star_counts != $_POST['star_counts']) {

                foreach ($get_log_table as $v) {

                    $starvote_log_data['sum_votes'] = $v->sum_votes / 2;

                    $where['id'] = $v->id;

                    $wpdb->update(STARVOTE_LOG_TABLE, $starvote_log_data, $where);

                }

            }

        }

    }

    

    echo "<script>history.back();</script>";

}



/**

 * get when client ip

 * @return string

 */

function get_ip() {

    static $realIP;

    if (isset($_SERVER)) {

        if (isset($_SERVER["HTTP_X_FORWARDED_FOR"])) {

            $realIP = explode(',', $_SERVER["HTTP_X_FORWARDED_FOR"]);

            $realIP = $realIP[0];

        } else if (isset($_SERVER["HTTP_CLIENT_IP"])) {

            $realIP = $_SERVER["HTTP_CLIENT_IP"];

        } else {

            $realIP = $_SERVER["REMOTE_ADDR"];

        }

    } else {

        if (getenv("HTTP_X_FORWARDED_FOR")) {

            $realIP = getenv("HTTP_X_FORWARDED_FOR");

        } else if (getenv("HTTP_CLIENT_IP")) {

            $realIP = getenv("HTTP_CLIENT_IP");

        } else {

            $realIP = getenv("REMOTE_ADDR");

        }

    }

    $_SERVER['REMOTE_ADDR'] = $realIP;

    return $realIP;

}



?>

 

style.css

@charset "utf-8";



#stars {

    overflow:hidden;

    margin-bottom: 5px;

}



#stars ul, #stars ul li {

    list-style: none;

    margin: 0;

    padding: 0;

    cursor: pointer;

}



#avg_score, #message {

    float:left;

    margin-left: 10px;

}

/*statistics-container----------------------------*/

#statistics-container {

    position: relative;

}



#msg {

    color: green;

    position: absolute;

    width: 100%;

    top: 0px;

    left: 300px;

}



#statistics-container #ratings-info-position {

    margin-left: 2px;

}



#statistics .comment_record_num {

    font-size: 16px;

    color: red;

}

/*star-small--------------------------------------*/

#stars #star-small li {

    background: url(../img/star.jpg) no-repeat 0 0;

    float:left;

    width: 20px;

    height: 20px;

    line-height: 20px;

}

#stars #star-small li.half {

    background-position: -21px -33px;

}

#stars #star-small li.none {

    background-position: -41px -33px;

}

#stars #star-small li.whole {

    background-position: -1px -33px;

}



/*star-big--------------------------------------*/

#stars #star-big li {

    background: url(../img/star.jpg) no-repeat 0 0;

    float:left;

    width: 30px;

    height: 30px;

    line-height: 20px;

}



#stars #star-big li.half {

    background-position: -31px -1px;

}

#stars #star-big li.none {

    background-position: -63px -1px;

}

#stars #star-big li.whole {

    background-position: 1px -1px;

}



/*----------------------------------------*/

#counter-container {



}

#counter-container .counter-label {

    line-height: 17px;

    float: left;

    min-width: 55px;

    font-size: 14px;

    margin-left: 2px;

}



#counter-container .counter-back {

    line-height: 17px;

    height: 17px;

    width: 200px;

    background-color: #ececec;

    float: left;

}



#counter-container .counter-count {

    line-height: 17px;

    height: 17px;

    margin-left: 5px;

    font-size: 14px;

}



#counter-container .counter-bar {

    line-height: 17px;

    height: 17px;

    background-color: #FDDB5A;

    float: left;

}

 

show_star.js

$(document).ready(function(){

    $("#stars ul li").on("mouseover", function(e){

        var thisnum = $(this).index();

        $("#stars ul li").each(function(){

            if ($(this).index() <= thisnum) {

                $(this).attr("oldClass", $(this).attr("class")).attr("class", "whole");

            } else {

               $(this).attr("oldClass", $(this).attr("class")).attr("class", "none");

            }

        });

    }).on("mouseout", function(){

       $("#stars ul li").each(function(){

            $(this).attr("class", $(this).attr("oldClass"));

        });



    }).on("click", function(e){

        var thisnum = $(this).index();

        $("#stars ul li").each(function(){

            if ($(this).index() <= thisnum) {

                $(this).attr("class", "whole").attr("oldClass", "whole");

            } else {

                $(this).attr("class", "none").attr("oldClass", "none");

            }

        });



        setTimeout(function(){

                $("#msg").fadeOut(1000);

            },2000);



        $("#avg_score").html(thisnum + 1 + " .0");   



        var user_id   = $("#ajaxStar").attr('user_id');

        var post_id   = $("#ajaxStar").attr('post_id');

        var sum_votes = $(e.target).attr('sum_votes');

        $.ajax({

            url : $("#ajaxStar").val(),

            dataType : 'html',

            method : 'post',

            data : 'post_id=' + post_id + '&user_id=' + user_id + '&sum_votes=' + sum_votes + '&insert_starvote_log= insert_starvote_log',

            success : function(data) {

                $("#statistics-container").html(data);

            }

        });

    });

});

 

star.jpg

jquery-1.10.2.js (网上下载一个jq文件,改名为 jquery-1.10.2.js) http://code.jquery.com/jquery-1.11.0.min.js

你可能感兴趣的:(wordpress)