Exemplo n.º 1
0
 function widget($args, $instance)
 {
     global $post;
     extract(array_merge(array('title' => '', 'number_posts' => 4, 'post_type' => 'post'), $instance));
     $q['posts_per_page'] = $number_posts;
     $q['paged'] = 1;
     $q['meta_key'] = '_post_like';
     $q['orderby'] = 'meta_value_num';
     $q['order'] = 'DESC';
     $q['ignore_sticky_posts'] = 1;
     query_posts($q);
     if (isset($before_widget)) {
         echo $before_widget;
     }
     echo '<aside class="widget tt_recent_posts tt-widget tt-most-liked">';
     if ($title != '') {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     echo '<ul>';
     while (have_posts()) {
         the_post();
         $comments = wp_count_comments($post->ID);
         $likes = blox_getmeta(get_the_ID(), 'post_like');
         echo '<li>';
         echo '<span class="widget-thumb">' . $likes . '</span>';
         echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a>';
         echo '<ul class="list-inline">
                 <li class="tt-widget-comments-number"><a href="#" title=""><i class="fa fa-comments"></i> ' . $comments->total_comments . '</a></li>
                 <li class="tt-widget-likes-number meta_like">' . get_post_like(get_the_ID()) . '</li>
               </ul>';
         echo '</li>';
     }
     echo '</ul>';
     echo '</aside>';
     if (isset($after_widget)) {
         echo $after_widget;
     }
     wp_reset_query();
 }
Exemplo n.º 2
0
function blox_post_like_hook()
{
    try {
        $post_id = (int) $_POST['post_id'];
        $count = (int) blox_getmeta($post_id, 'post_like');
        if ($post_id > 0) {
            blox_setmeta($post_id, 'post_like', $count + 1);
        }
        echo "1";
    } catch (Exception $e) {
        echo "-1";
    }
    exit;
}