• Stars
    star
    114
  • Rank 308,031 (Top 7 %)
  • Language
    PHP
  • Created over 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Enables you to display how many times a post/page had been viewed.

WP-PostViews

Contributors: GamerZ
Donate link: https://lesterchan.net/site/donation/
Tags: views, hits, counter, postviews
Requires at least: 4.0
Tested up to: 6.2
Stable tag: 1.77

Enables you to display how many times a post/page had been viewed.

Description

Usage

  1. Open wp-content/themes/<YOUR THEME NAME>/index.php
  2. You may place it in archive.php, single.php, post.php or page.php also.
  3. Find: <?php while (have_posts()) : the_post(); ?>
  4. Add Anywhere Below It (The Place You Want The Views To Show): <?php if(function_exists('the_views')) { the_views(); } ?>
  5. Or you can use the shortcode [views] or [views id="1"] (where 1 is the post ID) in a post
  6. Go to WP-Admin -> Settings -> PostViews to configure the plugin.

Development

https://github.com/lesterchan/wp-postviews/

Translations

http://dev.wp-plugins.org/browser/wp-postviews/i18n/

Credits

Donations

I spent most of my free time creating, updating, maintaining and supporting these plugins, if you really love my plugins and could spare me a couple of bucks, I will really appreciate it. If not feel free to use it without any obligations.

Changelog

Version 1.77

  • NEW: Use Vanilla JS. Props @JiveDig
  • NEW: Bump to WordPress 6.2
  • NEW: Support views under fields for Rest API. Props @vitro-mod

Version 1.76.1

  • NEW: Add Post Author in views template
  • NEW: Bump for WordPress 5.3

Version 1.76

  • NEW: Added postviews_should_count filter
  • FIXED: Change to (int) from intval() and use sanitize_key() with it.

Version 1.75

  • NEW: Use WP_Query() for most/least viewed posts

Version 1.74

  • NEW: Bump WordPress 4.7
  • NEW: Template variable %POST_CATEGORY_ID%. It returns Post's Category ID. If you are using Yoast SEO Plugin, it will return the priority Category ID. Props @FunFrog-BY

Version 1.73

  • FIXED: In preview mode, don't count views

Version 1.72

  • NEW: Add %POST_THUMBNAIL% to template variables

Version 1.71

  • FIXED: Notices in Widget Constructor for WordPress 4.3

Version 1.70

  • FIXED: Integration with WP-Stats

Version 1.69

  • NEW: Shortcode [views] or [views id="POST_ID"]` to embed view count into post
  • NEW: Added template variable %VIEW_COUNT_ROUNDED% to support rounded view count like 10.1k or 11.2M

Version 1.68

  • NEW: Added action hook 'postviews_increment_views' and 'postviews_increment_views_ajax'
  • NEW: Allow custom post type to be chosen under the widget

Version 1.67

  • NEW: Allow user to not use AJAX to update the views even though WP_CACHE is true

Version 1.66

  • NEW: Supports MultiSite Network Activation
  • NEW: Add %POST_DATE% and %POST_TIME% to template variables
  • NEW: Add China isearch engines bots
  • NEW: Ability to pass in an array of post types for get_most/least_*() functions. Props Leo Plaw.
  • FIXED: Moved uninstall to uninstall.php and hence fix missing nonce. Props Julio Potier.
  • FIXED: Notices and better way to get views from meta. Props daankortenbach.
  • FIXED: No longer needing add_post_meta() if update_post_meta() fails.

Version 1.65 (02-06-2013)

  • FIXED: Views not showing in WP-Admin if "Display Options" is not set to "Display to everyone"

Upgrade Notice

N/A

Screenshots

  1. PostViews
  2. Admin - PostViews Options

Frequently Asked Questions

How To View Stats With Widgets?

  • Go to WP-Admin -> Appearance -> Widgets
  • The widget name is Views.

To Display Least Viewed Posts

<?php if (function_exists('get_least_viewed')): ?>
	<ul>
		<?php get_least_viewed(); ?>
	</ul>
<?php endif; ?>
  • The first value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example array('post', 'page').
  • The second value you pass in is the maximum number of post you want to get.
  • Default: get_least_viewed('both', 10);

To Display Most Viewed Posts

<?php if (function_exists('get_most_viewed')): ?>
	<ul>
		<?php get_most_viewed(); ?>
	</ul>
<?php endif; ?>
  • The first value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example array('post', 'page').
  • The second value you pass in is the maximum number of post you want to get.
  • Default: get_most_viewed('both', 10);

To Display Least Viewed Posts By Tag

<?php if (function_exists('get_least_viewed_tag')): ?>
	<ul>
		<?php get_least_viewed_tag(); ?>
	</ul>
<?php endif; ?>
  • The first value you pass in is the tag id.
  • The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example array('post', 'page').
  • The third value you pass in is the maximum number of post you want to get.
  • Default: get_least_viewed_tag(1, 'both', 10);

To Display Most Viewed Posts By Tag

<?php if (function_exists('get_most_viewed_tag')): ?>
	<ul>
		<?php get_most_viewed_tag(); ?>
	</ul>
<?php endif; ?>
  • The first value you pass in is the tag id.
  • The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example array('post', 'page').
  • The third value you pass in is the maximum number of post you want to get.
  • Default: get_most_viewed_tag(1, 'both', 10);

To Display Least Viewed Posts For A Category

<?php if (function_exists('get_least_viewed_category')): ?>
	<ul>
		<?php get_least_viewed_category(); ?>
	</ul>
<?php endif; ?>
  • The first value you pass in is the category id.
  • The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example array('post', 'page').
  • The third value you pass in is the maximum number of post you want to get.
  • Default: get_least_viewed_category(1, 'both', 10);

To Display Most Viewed Posts For A Category

<?php if (function_exists('get_most_viewed_category')): ?>
	<ul>
		<?php get_most_viewed_category(); ?>
	</ul>
<?php endif; ?>
  • The first value you pass in is the category id.
  • The second value you pass in is the post type that you want. If you want to get every post types, just use 'both'. It also supports PHP array: example array('post', 'page').
  • The third value you pass in is the maximum number of post you want to get.
  • Default: get_most_viewed_category(1, 'both', 10);

To Sort Most/Least Viewed Posts

  • You can use: <?php query_posts( array( 'meta_key' => 'views', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); ?>
  • Or pass in the variables to the URL: http://yoursite.com/?v_sortby=views&v_orderby=desc
  • You can replace DESC with ASC if you want the least viewed posts.

To Display Updating View Count With LiteSpeed Cache

Use: <div id="postviews_lscwp"></div> to replace <?php if(function_exists('the_views')) { the_views(); } ?>. NOTE: The id can be changed, but the div id and the ajax function must match. Replace the ajax query in wp-content/plugins/wp-postviews/postviews-cache.js with

jQuery.ajax({
    type:"GET",
    url:viewsCacheL10n.admin_ajax_url,
    data:"postviews_id="+viewsCacheL10n.post_id+"&action=postviews",
    cache:!1,
    success:function(data) {
        if(data) {
            jQuery('#postviews_lscwp').html(data+' views');
        }
   }
});

Purge the cache to use the updated pages.

To Get Views With REST API

You can obtain the number of post views by adding views to your _fields parameter: /wp/v2/posts?_fields=views,title

More Repositories

1

wp-sweep

WP-Sweep allows you to clean up unused, orphaned and duplicated data in your WordPress. It also optimizes your database tables.
PHP
153
star
2

wp-pagenavi

Adds a more advanced paging navigation interface to your WordPress blog.
PHP
133
star
3

wp-postratings

Adds an AJAX rating system for your WordPress blog's post/page.
PHP
123
star
4

telegram-bot

Telegram Bot using AWS API Gateway and AWS Lambda
JavaScript
123
star
5

wp-polls

Adds an AJAX poll system to your WordPress blog. You can also easily add a poll into your WordPress's blog post/page.
PHP
93
star
6

wp-dbmanager

Allows you to optimize database, repair database, backup database, restore database, delete backup database , drop/empty tables and run selected queries. Supports automatic scheduling of backing up, optimizing and repairing of database.
PHP
71
star
7

slack-bot

Slack Bot using AWS API Gateway and AWS Lambda
JavaScript
56
star
8

wp-useronline

Enable you to display how many users are online on your WordPress blog with detailed statistics.
PHP
36
star
9

linkedin-pdf-resume-parser

Parse LinkedIn PDF Resume and extract out name, email, education and work experiences.
PHP
27
star
10

wp-showhide

Allows you to embed content within your blog post via WordPress ShortCode API and toggling the visibility of the cotent via a link.
PHP
24
star
11

rendeer

Puppeteer x Prerender
JavaScript
24
star
12

gamerz-file-explorer

Enables you to browse and search for folders/files on the web just like Windows Explorer.
PHP
23
star
13

wp-ban

Ban users by IP, IP Range, host name, user agent and referrer url from visiting your WordPress's blog.
PHP
22
star
14

wp-print

Displays a printable version of your WordPress blog's post/page.
PHP
21
star
15

wp-serverinfo

Display your host's PHP, MYSQL & memcached (if installed) information on your WordPress dashboard.
PHP
17
star
16

wp-downloadmanager

Adds a simple download manager to your WordPress blog.
PHP
17
star
17

wp-email

Allows people to recommend/send your WordPress blog's post/page to a friend.
PHP
14
star
18

wp-instantarticles

WP-InstantArticles generates a RSS feed of your WordPress posts as Instant Articles for Facebook to consume.
PHP
10
star
19

wp-draftsforfriends

Now you don't need to add friends as users to the blog in order to let them preview your drafts
PHP
10
star
20

products-stock-checker

Just a personal project to check products price and stock availability on Razer Online Stores and Lazada.
JavaScript
9
star
21

wp-relativedate

Displays relative date alongside with your post/comments actual date. Like 'Today', 'Yesterday', '2 Days Ago', '2 Weeks Ago', '2 'Seconds Ago', '2 Minutes Ago', '2 Hours Ago'.
PHP
6
star
22

wp-stats

Display your WordPress blog statistics. Ranging from general total statistics, some of my plugins statistics and top 10 statistics.
PHP
5
star
23

wp-commentnavi

Adds a more advanced paging navigation for your comments to your WordPress 2.8 and above blog.
PHP
4
star
24

wp-sticky

[DEPRECATED] Adds a sticky post feature to your WordPress's blog.
PHP
3
star
25

wp-pluginsused

Display WordPress plugins that you currently have (both active and inactive) onto a post/page.
PHP
3
star
26

paw-base64urlencode

A Paw Extension that allows you to generate a websafe url from a base64 encoding. Used mainly for GrabPay API.
JavaScript
2
star
27

lesterchan

Lester Chan's GitHub Profile
2
star
28

smartthings

Lester Chan's SmartThings Apps & Custom Device Handlers
Groovy
2
star
29

paw-rsa

A Paw Extension that allows you to encrypt/decrypt using RSA Public/Private Key.
JavaScript
2
star
30

gp-php-sdk-sample

GP PHP SDK Sample
PHP
1
star
31

paw-popsignature

A Paw Extension that allows you to generate a X-GID-AUX-POP HMAC signature. Used mainly for GrabPay API.
JavaScript
1
star
32

wp-wap

[DEPRECATED] Browse your WordPress's blog entries on a WAP enabled mobile phone.
PHP
1
star
33

wp-migme

Share a post to migme's Miniblog whenever you publish a post in WordPress.
PHP
1
star
34

freemyinternet

Automatically places the FreeMyInternet banner from FreeMyInternet.com on your WordPress website. The blogging community will be organising a protest and online black out on Thursday 6th June 2013, 0001 to 6th June 2013, 2359 against the new licensing by the Media Development Authority of Singapore.
PHP
1
star