• Hi!

    First: great plugin, very simple but usefull.

    I wrote a little additional function to this plugin. I’ve noticed that if i want to show posts views on main page (or anywhere except single.php) that incerase view property even if no one see the article. So I’ve decided to add function echo_post_views_not_counted() with is not adding view info to db. Now on every page I use this function, and on page single.php im using normal echo_post_views(). Maybe for someone it will be usefull.

    Paste the following function in wp-post-view.php file, below echo_post_views() function (in my case 19.03.2013 – ver 1.0) its 125 line).

    if (!function_exists('echo_post_views_not_counted')) {
    
        /**
         * Echo, print or display the views of the post.
         * @param <type> $post_id
         */
        function echo_post_views_not_counted($post_id) {
            if ($post_id) {
                $views = wp_get_post_views($post_id);
                echo number_format_i18n($views);
            } else {
                echo 0;
            }
        }
    
    }

    Use simply like other functions:

    <?php echo_post_views_not_counted($post->ID); ?>
    or
    <?php echo_post_views_not_counted(get_the_ID()); ?>

    http://wordpress.org/extend/plugins/wp-post-view/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘One additional usefull function’ is closed to new replies.