function boston_favourite()
{
    $post_id = $_POST['post_id'];
    $class = boston_favourited_class($post_id);
    if ($class == 'star-o') {
        add_post_meta($post_id, 'favourited_for', $_SERVER['REMOTE_ADDR'] . '_' . $post_id);
        $class = 'star';
    } else {
        delete_post_meta($post_id, 'favourited_for', $_SERVER['REMOTE_ADDR'] . '_' . $post_id);
        $class = 'star-o';
    }
    $post_favs = get_post_meta($post_id, 'favourited_for');
    echo '<i class="fa fa-' . esc_attr($class) . '"></i> ' . count($post_favs);
    die;
}
Exemple #2
0
                                            <a href="<?php 
        the_permalink();
        ?>
#comments">
                                                <i class="fa fa-comment-o"></i><?php 
        comments_number(0, 1, '%');
        ?>
                                            </a>
                                        </span>
                                        <span class="favourites">
                                            <a href="javascript:;" class="favourites-click" data-post_id="<?php 
        the_ID();
        ?>
">
                                                <i class="fa fa-<?php 
        echo boston_favourited_class();
        ?>
"></i><?php 
        echo boston_get_favourites_count();
        ?>
                                            </a>
                                        </span>
                                    </div>
                                </div>                                
                            </div>
                            <?php 
    }
    echo '</div></div>';
}
wp_reset_postdata();
?>
    function widget($args, $instance)
    {
        extract($args);
        $instance = wp_parse_args((array) $instance, array('title' => '', 'text' => ''));
        $title = esc_attr($instance['title']);
        $text = esc_attr($instance['text']);
        $title = !empty($instance['title']) ? $instance['title'] : __('Posts', 'boston');
        $title = apply_filters('widget_title', $title, $instance, $this->id_base);
        $number = !empty($instance['number']) ? absint($instance['number']) : 5;
        if (!$number) {
            $number = 5;
        }
        ?>
		<?php 
        echo $before_widget;
        ?>
		<?php 
        if ($title) {
            echo $before_title . $title . $after_title;
        }
        ?>
		
		<?php 
        $r = new WP_Query(apply_filters('widget_posts_args', array('posts_per_page' => $number, 'no_found_rows' => true, 'post_status' => 'publish', 'meta_key' => 'wpb_post_views_count', 'orderby' => 'meta_value_num', 'ignore_sticky_posts' => true)));
        if ($r->have_posts()) {
            ?>
			<ul class="list-unstyled">
			<?php 
            while ($r->have_posts()) {
                $r->the_post();
                ?>
				<div class="popular-post">
				    <div class="pp-image">
				    	<?php 
                the_post_thumbnail('widget-box', array('class' => 'img-responsive'));
                ?>
				    </div>

				    <a href="javascript:;" class="overlay"></a>

				    <div class="pp-header">
				        <h4><a href="<?php 
                the_permalink();
                ?>
"><?php 
                the_title();
                ?>
</a></h4>
				        <span class="author"><?php 
                _e('by ', 'boston');
                ?>
				        	<a href="<?php 
                echo esc_url(get_author_posts_url(get_the_author_meta('ID')));
                ?>
">
				        		<?php 
                $name = get_the_author_meta('display_name');
                if (strlen($name) > 15) {
                    $name = substr($name, 0, 15);
                    $name .= '...';
                }
                echo esc_html($name);
                ?>
				        	</a>
				        </span>
				        <span class="comments">
				        	<a href="<?php 
                the_permalink();
                ?>
#comments">
				        		<i class="fa fa-comment-o"></i><?php 
                comments_number(0, 1, '%');
                ?>
				        	</a>
				        </span>
				        <span class="favourites">
				        	<a href="javascript:;" class="favourites-click" data-post_id="<?php 
                the_ID();
                ?>
">
				        		<i class="fa fa-<?php 
                echo boston_favourited_class();
                ?>
"></i><?php 
                echo boston_get_favourites_count();
                ?>
				        	</a>
				        </span>
				    </div>
				</div>				
				<?php 
            }
            ?>
			</ul>
		<?php 
        }
        ?>
		
		<?php 
        echo $after_widget;
        wp_reset_postdata();
    }