Example #1
0
function the_views($display = true, $prefix = '', $postfix = '', $always = false)
{
    $post_views = intval(post_custom('views'));
    $views_options = get_option('views_options');
    if ($always || should_views_be_displayed($views_options)) {
        $output = $prefix . str_replace('%VIEW_COUNT%', number_format_i18n($post_views), $views_options['template']) . $postfix;
        if ($display) {
            echo apply_filters('the_views', $output);
        } else {
            return apply_filters('the_views', $output);
        }
    } elseif (!$display) {
        return '';
    }
}
Example #2
0
function the_views($display = true, $prefix = '', $postfix = '', $always = false, $visible_template = false)
{
    $post_views = intval(get_post_meta(get_the_ID(), 'views', true));
    $views_options = get_option('views_options');
    if ($visible_template) {
        $views_options['template'] = '%VIEW_COUNT%';
    }
    if ($always || should_views_be_displayed($views_options)) {
        $output = $prefix . str_replace(array('%VIEW_COUNT%', '%VIEW_COUNT_ROUNDED%'), array(number_format_i18n($post_views), postviews_round_number($post_views)), stripslashes($views_options['template'])) . $postfix;
        //		file_put_contents('test',json_encode($views_options));
        if ($display) {
            echo apply_filters('the_views', $output);
        } else {
            return apply_filters('the_views', $output);
        }
    } elseif (!$display) {
        return '';
    }
}
 /**
  * 判断是否需要展示浏览量
  * return true/false
  */
 public function should_views_be_displayed($views_options = null)
 {
     if ($this->checkPostViewPlugin()) {
         return should_views_be_displayed($views_options);
     }
     if ($views_options == null) {
         $views_options = get_option('views_options');
     }
     return true;
     $display_option = 0;
     if (is_home()) {
         if (array_key_exists('display_home', $views_options)) {
             $display_option = $views_options['display_home'];
         }
     } elseif (is_single()) {
         if (array_key_exists('display_single', $views_options)) {
             $display_option = $views_options['display_single'];
         }
     } elseif (is_page()) {
         if (array_key_exists('display_page', $views_options)) {
             $display_option = $views_options['display_page'];
         }
     } elseif (is_archive()) {
         if (array_key_exists('display_archive', $views_options)) {
             $display_option = $views_options['display_archive'];
         }
     } elseif (is_search()) {
         if (array_key_exists('display_search', $views_options)) {
             $display_option = $views_options['display_search'];
         }
     } else {
         if (array_key_exists('display_other', $views_options)) {
             $display_option = $views_options['display_other'];
         }
     }
     return $display_option == 0 || $display_option == 1 && is_user_logged_in();
 }