Beispiel #1
0
<?php

require 'init.php';
$post_id = $_POST['post_id'];
add_like_to_post($post_id, get_current_user_id());
echo get_count_of_likes_by_post_id($post_id);
Beispiel #2
0
function like_button($post_id, $user_id)
{
    $like_count = get_count_of_likes_by_post_id($post_id);
    $users = get_users_who_liked_post($post_id);
    $class = 'btn like-button';
    if (is_liked($post_id, $user_id)) {
        $class .= ' liked';
    }
    if ($user_id) {
        $class .= ' logged-in';
    } else {
        $class .= ' logged-out';
    }
    ?>
        <button class="<?php 
    echo $class;
    ?>
" data-content="<?php 
    echo escape_html(links_for_users($users));
    ?>
" data-post="<?php 
    echo escape_html($post_id);
    ?>
">
            Мені подобається
            <span class="glyphicon glyphicon-heart heart"></span>
            <span class="count"><?php 
    echo escape_html($like_count);
    ?>
</span>
        </button>
    <?php 
}