Basic introduction
Arguably, the best and most popular WordPress views counting plug-in is WP-Postviews, which can count the views of each article and get a list of the most popular (most viewed) articles.
WP-Postviews can set statistical objects: anyone, anonymous visitors, logged in users, and can exclude statistical spider crawlers.
The latest version of WP-Postviews already supports caching. Even if you use caching plug-ins such as WP Super Cache for caching, it can still count normally.
How to use
1. Open wp-content/themes/<your theme name>/index.php
You can put the code in single.php, post.php or page.php.
2. Find:
<?php while (have_posts()) : the_post(); ?>
3. Add at the appropriate place:
<?php if(function_exists(’the_views’)) { the_views(); } ?>
Open ‘Settings -> Post Views’ and set the parameters of the plugin.
View status (using Widget):
Enable WP-PostViews Widget plugin
Open ‘Appearance -> Widgets‘
Drag and drop Most Viewed Widget to the sidebar
You can configure the Most Viewed Widget plugin via the configure button.
Click "Save Changes"
·Show statistics:
Show most viewed
·usage:
<?php if (function_exists('get_most_viewed')): ?>
<?php get_most_viewed(); ?>
<?php endif; ?>
·The first parameter: the type of displayed statistics 'post' (log), 'page' (page) or 'both' (both displayed) The second parameter: the number to be displayed
·Default: get_most_viewed(‘both’, 10);
Display the most viewed articles or pages in a category
·usage:
<?php if (function_exists('get_most_viewed_category')): ?>
<?php get_most_viewed_category(); ?>
<?php endif; ?>
·The first parameter: the ID of the category, which can be seen in "Management->Category". The second parameter: the type of statistics displayed, 'post' (log), 'page' (page) or 'both' (both displayed) The third parameter: the number to be displayed
·Default: get_most_viewed_category(1, ‘both’, 10);
Screenshot display
it works
it works
it works