Example #1
1
/**
 * Template tag for getting a specific post's view count.  It will default to the current post in The 
 * Loop.  To use the 'text' argument, either pass a nooped plural using _n_noop() or a single text string.
 *
 * @since  1.0.0
 * @access public
 * @param  array  $args
 * @return string
 */
function ev_get_post_views($args = array())
{
    $defaults = array('post_id' => get_the_ID(), 'before' => '', 'after' => '', 'text' => _n_noop('%s View', '%s Views', 'entry-views'), 'wrap' => '<span %s>%s</span>');
    $args = wp_parse_args($args, $defaults);
    $views = ev_get_post_view_count($args['post_id']);
    $text = is_array($args['text']) ? translate_nooped_plural($args['text'], $views) : $args['text'];
    $html = sprintf($args['wrap'], 'class="entry-views" itemprop="interactionCount" itemscope="itemscope" itemtype="http://schema.org/UserPageVisits"', sprintf($text, $views));
    return $args['before'] . $html . $args['after'];
}
Example #2
0
function barcelona_get_post_views($post_id = NULL)
{
    $barcelona_views = 0;
    if (is_null($post_id)) {
        $post_id = get_the_ID();
    }
    if (function_exists('ev_get_post_view_count')) {
        $barcelona_views = ev_get_post_view_count($post_id);
        if (!is_numeric($barcelona_views)) {
            $barcelona_views = 0;
        }
    }
    if (is_single()) {
        $barcelona_views++;
    }
    return intval($barcelona_views);
}
Example #3
0
 function vce_get_meta_data($layout = 'lay-a', $force_meta = false)
 {
     if (!$force_meta) {
         $map = array('lay-a' => 'lay_a', 'lay-b' => 'lay_b', 'lay-c' => 'lay_c', 'lay-d' => 'lay_d', 'lay-e' => 'lay_e', 'lay-g' => 'lay_g', 'lay-fa-grid' => 'lay_fa_grid', 'lay-fa-big' => 'lay_fa_big', 'single' => 'single');
         //Layouts theme options
         $layout_metas = array_filter(vce_get_option($map[$layout] . '_meta'));
     } else {
         //From widget or anywhere you want
         $layout_metas = array($force_meta => '1');
     }
     $output = '';
     if (!empty($layout_metas)) {
         foreach ($layout_metas as $mkey => $active) {
             $meta = '';
             switch ($mkey) {
                 case 'date':
                     $meta = '<span class="updated">' . vce_get_date() . '</span>';
                     break;
                 case 'author':
                     $meta = '<span class="vcard author"><span class="fn">' . __vce('by_author') . ' <a href="' . get_author_posts_url(get_the_author_meta('ID')) . '">' . get_the_author_meta('display_name') . '</a></span></span>';
                     break;
                 case 'comments':
                     if (comments_open() || get_comments_number()) {
                         ob_start();
                         comments_popup_link(__vce('no_comments'), __vce('one_comment'), __vce('multiple_comments'));
                         $meta = ob_get_contents();
                         ob_end_clean();
                     } else {
                         $meta = '';
                     }
                     break;
                 case 'views':
                     global $wp_locale;
                     $thousands_sep = isset($wp_locale->number_format['thousands_sep']) ? $wp_locale->number_format['thousands_sep'] : ',';
                     $meta = function_exists('ev_get_post_view_count') ? number_format(absint(str_replace($thousands_sep, '', ev_get_post_view_count(get_the_ID())) + vce_get_option('views_forgery')), 0, '', ',') . ' ' . __vce('views') : '';
                     break;
                 case 'rtime':
                     $meta = vce_read_time(get_the_content());
                     if (!empty($meta)) {
                         $meta .= ' ' . __vce('min_read');
                     }
                     break;
                 default:
                     break;
             }
             if (!empty($meta)) {
                 $output .= '<div class="meta-item ' . $mkey . '">' . $meta . '</div>';
             }
         }
     }
     return $output;
 }