• 2019-01-19 19:58:48
  • 7,782 次阅读
  • 稿源:天马行空


add_action('wp_ajax_nopriv_favorite_praise', 'favorite_praise');
add_action('wp_ajax_favorite_praise', 'favorite_praise');
function favorite_praise(){
    global $wpdb,$post;
    $id = $_POST["um_id"];
    $action = $_POST["um_action"];
    if ( $action == 'ding'){
        $specs_raters = get_post_meta($id,'favorite_praise',true);
        $expire = time() + 99999999;
        $domain = ($_SERVER['HTTP_HOST'] != 'localhost') ? $_SERVER['HTTP_HOST'] : false; // make cookies work with localhost
        if (!$specs_raters || !is_numeric($specs_raters)) {
            update_post_meta($id, 'favorite_praise', 1);
        else {
            update_post_meta($id, 'favorite_praise', ($specs_raters + 1));
        echo get_post_meta($id,'favorite_praise',true);


$.fn.postLike = function() {
    if ($(this).hasClass('done')) {
        return false;
    } else {
        var id = $(this).data("id"),
        action = $(this).data('action'),
        rateHolder = $(this).children('.count');
        var ajax_data = {
            action: "favorite_praise",
            um_id: id,
            um_action: action
        $.post("/wp-admin/admin-ajax.php", ajax_data,
        function(data) {
        return false;
$(document).on("click", ".favoritePraise",
    function() {



<div class="post-like">
    <a href="javascript:;" data-action="ding" data-id="<?php the_ID(); ?>" class="favoritePraise <?php if(isset($_COOKIE['favorite_praise_'.$post->ID])) echo 'done';?>">喜欢 <span class="count">
        <?php if( get_post_meta($post->ID,'favorite_praise',true) ){
            echo get_post_meta($post->ID,'favorite_praise',true);
                } else {
echo '0';


.post-like a{ background-color:#21759B;border-radius: 3px;color: #FFFFFF;font-size: 12px;padding: 5px 10px;text-decoration: none;outline:none}
.post-like a.done, .post-like a:hover{background-color:#eee;color:#21759B;}
.post-like a.done{cursor:not-allowed}
喜欢 82

文章评论 (6)

  1. Ishtar Company LLC说道:

    For most up-to-date information you have to go to see world wide web
    and on internet I found this web page as a best website
    for latest updates.

    [1楼]网友 Linux | Chrome 67.0.3396.87   
    • star说道:

      Oh,I see

      [2楼]网友 Windows 7 | 搜狗浏览器 2.X      
  2. WordPress说道:

    Nߋt onjly that sometimes new theme add neww functionality to yоuг website.

    Worɗ – Prеss Plugin is really a program that is put together by the plugin developers thɑt enable you to addd a huge selectіon of features, effects and benefits for your bloɡ.
    They are used to deliver certain functionalities for thе CMS which otherwise
    would ϲall for а development intensive activity.

    [3楼]网友 Linux | Firefox 52.9   
  3. sodium bicarbonate说道:

    I don’t even know the way I ended up right here,
    however I thought this put up used too bbe good.
    I don’t realize who you’re however certainly you are going
    to a famous blogger in thee event you aren’t already.

    [4楼]网友 Windows NT | Chrome 63.0.3239.132   
  4. Lashay说道:

    Wow, marvelous blog layout! How long have you been running a blog for?
    you make running a blog glance easy. The full look of your website is magnificent, as smartly as the content!

    [5楼]网友 Mac OS X | Chrome 63.0.3239.108   
    • star说道:

      Thank you for your praise, it’s been more than two and a half years.

      [6楼]网友 Windows 7 | 搜狗浏览器 2.X      


大眼 可爱 大笑 坏笑 害羞 发怒 折磨 快哭了 大哭 白眼 晕 流汗 困 腼腆 惊讶 憨笑 色 得意 骷髅 囧 睡觉 眨眼 亲亲 疑问 闭嘴 难过 淡定 抗议 鄙视 猪头