Post Views Usage

1. My Sample Code

The following are codes being used in my blog:

ziming

// the following are codes in index.php, pls refer to http://xieziming.com
 
< ?php
 
if(function_exists('get_post_views')) { 
        _e(' , Preview: '); 
        echo get_post_total_previews();
}
 
if(function_exists('get_post_views')) { 
        _e(' , Index: '); 
        echo get_post_total_robotviews();
} 
 
if(function_exists('get_post_views')) { 
        _e(' , Read: '); 
        echo get_post_total_views();
}
 
?>

ziming

// the following are codes in single.php, pls refer to http://xieziming.com/archives/1472.html
 
< ?php
 
if(function_exists('get_post_views')) {  
      _e('Preview : '); 
      echo get_post_today_previews()." / ". get_post_total_previews();
      _e(' ,Read : '); 
      echo get_post_today_views()." / ".get_post_total_views();
} 
 
if(function_exists('get_post_views')) {  
      _e('Index : '); 
      echo get_post_today_robotviews()." / 
      ".get_post_total_robotviews();
} 
 
?>

ziming

< ?php
 
if(function_exists('get_post_last_viewed_time')) {  
       echo get_post_last_viewed_time('timespan');
       _e(', this page was being read. ');
} 
 
?>
16 hours ago, this page was being read.


    Order by : Newer | Older

  1. accutane epharmacies 2014-10-21
    @18:44 Reply

    Wham bam thank you, ma’am, my questions are answered!

  2. Henk 2013-06-06
    @04:00 Reply

    Hi, I wish to delete the history. But when I go to Options the year selector is empty? How do I solve that?

  3. Suny Tse2013-06-06
    @23:53   to  HenkReply

    Only the history data of the past year can be deleted. In other words, it can only delete whole year's data, but not past month/week...

  4. Gaston 2012-09-20
    @23:50 Reply

    Hi Suny Tse:
    I did a fix on post_views_orderby($content) where I’m getting a string “wp_posts.post_date DESC” on $content.
    function post_views_orderby($content) {
    if (is_string($content)) {
    $orderby = trim(strstr($content, ‘ ‘));
    } else {
    $orderby = strtolower(trim(addslashes(get_query_var(‘v_orderby’))));
    }

    $ordertype = trim(addslashes(get_query_var(‘v_ordertype’)));
    echo $content;
    if(empty($ordertype) || ($ordertype != ‘latest_view_time’ && $ordertype != ‘views’)) {
    $ordertype = ‘views’;
    }

    if(empty($orderby) || ($orderby != ‘ASC’ && $orderby != ‘DESC’)) {
    $orderby = ‘DESC’;
    }
    $content = ” “.$ordertype.” “.$orderby;

    return $content;
    }

    Thanks!

  5. Suny Tse2012-09-21
    @01:01   to  GastonReply

    Hi Gaston, i have done some change on the code: if(empty($orderby) || ($orderby != 'asc' && $orderby != 'desc')) { $orderby = 'desc'; }else{ $orderby = 'asc'; } It should be ok now.

  6. Suny Tse2012-09-21
    @01:04   to  GastonReply

    And i have committed the changes to wordpress repository(without new version id), could you download the latest pack and have a test?

  7. Gaston 2012-09-20
    @03:49 Reply

    This is the query, I see “GROUP BY wp_posts.ID ORDER BY views desc LIMIT 0, 16” in the last portion of SQL :
    [request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.*, (wp_post_views_realtime.post_views_total + 0) AS views FROM wp_posts INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id) LEFT JOIN wp_post_views_realtime ON wp_post_views_realtime.post_id = wp_posts.ID WHERE 1=1 AND wp_posts.post_type = ‘jardin’ AND (wp_posts.post_status = ‘publish’) AND ( (wp_postmeta.meta_key = ‘_royal_meta’ AND CAST(wp_postmeta.meta_value AS CHAR) LIKE ‘%on%’) ) AND wp_post_views_realtime.view_type = ‘normal’ AND wp_post_views_realtime.output_type = ‘content’ AND wp_post_views_realtime.post_views_total != 0 GROUP BY wp_posts.ID ORDER BY views desc LIMIT 0, 16

  8. Gaston 2012-09-20
    @02:26 Reply

    Hi Suny Tse,

    I’m trying to change the sort of the posts (with WP_Query) sorting by views and ordering DESC/ASC but, I allways get DESC order in the post loop.

    I have this function to query the posts:

    function get_things_by_type($tipo = ‘pub’, $orderby = ‘date’, $ord = ‘DESC’, $cant = -1){
    if ($tipo == ‘pub’){
    $compara = ‘LIKE’;
    }else{
    $compara = ‘NOT LIKE’;
    }
    //Query to retrieve the pages
    $args = array(
    ‘post_type’ => ‘thing’,
    ‘posts_per_archive_page ‘ => $cant,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => $cant,
    ‘orderby’ => $orderby,
    ‘order’ => $ord,
    ‘meta_query’ => array(
    array(
    ‘key’ => ‘_royal_meta’,
    ‘value’ => ‘on’,
    ‘compare’ => $compara
    )
    )
    );
    if ($orderby == ‘views’){
    $views = array (
    ‘v_sortby’ => ‘views’,
    ‘v_orderby’ => $ord,
    ‘v_ordertype’ => ‘views’,
    ‘v_timespan’ => ‘total’,
    );
    $args = wp_parse_args( $args, $views );
    extract( $args, EXTR_SKIP );
    unset($args[orderby]);
    unset($args[order]);
    array_filter($args);

    //looking the query, ASC/DESC is ok
    print_r($args);
    }

    return new WP_Query($args);
    }
    My pulldown is sending ASC ok, but I allways get DESC. These are the arguments:
    Array ( [v_sortby] => views [v_orderby] => ASC [v_ordertype] => views [v_timespan] => total [post_type] => jardin [posts_per_archive_page ] => 16 [post_status] => publish [posts_per_page] => 16 [meta_query] => Array ( [0] => Array ( [key] => _royal_meta [value] => on [compare] => LIKE ) ) )

    Do you have any idea to fix it?

    Thanks, Gaston

  9. << PrePage Current: 1 / 6 NextPage >>

Subscribe to Comments