Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To Show WordPress Post View Count Without A Plugin
#1
Tutorial 1
Use this code in functions.php


PHP Code:
function rm_post_view_count(){
 if ( 
is_single() ){
 global 
$post;
 
$count_post esc_attrget_post_meta$post->ID'_post_views_count'true) );
 if( 
$count_post == ''){
 
$count_post 1;
 
add_post_meta$post->ID'_post_views_count'$count_post);
 }else{
 
$count_post = (int)$count_post 1;
 
update_post_meta$post->ID'_post_views_count'$count_post);
 }
 }
}
add_action('wp_head''rm_post_view_count'); 

Or use this code in your single.php



PHP Code:
if ( is_single() ){
 global 
$post;
 
$count_post esc_attrget_post_meta$post->ID'_post_views_count'true) );
 if( 
$count_post == ''){
 
$count_post 1;
 
add_post_meta$post->ID'_post_views_count'$count_post);
 }else{
 
$count_post = (int)$count_post 1;
 
update_post_meta$post->ID'_post_views_count'$count_post);
 }
 } 
then use this code for display post counter



PHP Code:
global $post;
$visitor_count get_post_meta$post->ID'_post_views_count'true);
if( 
$visitor_count == '' ){ $visitor_count 0; }
if( 
$visitor_count >= 1000 ){
 
$visitor_count round( ($visitor_count/1000), );
 
$visitor_count $visitor_count.'k';
}
echo 
esc_attr($visitor_count); 

Tutorial 2

Add this code your functions.php

PHP Code:
// function to display number of posts.
function getPostViews($postID){
 
   $count_key 'post_views_count';
 
   $count get_post_meta($postID$count_keytrue);
 
   if($count==''){
 
       delete_post_meta($postID$count_key);
 
       add_post_meta($postID$count_key'0');
 
       return "0 View";
 
   }
 
   return $count.' Views';
}
 
// function to count views.
function setPostViews($postID) {
 
   $count_key 'post_views_count';
 
   $count get_post_meta($postID$count_keytrue);
 
   if($count==''){
 
       $count 0;
 
       delete_post_meta($postID$count_key);
 
       add_post_meta($postID$count_key'0');
 
   }else{
 
       $count++;
 
       update_post_meta($postID$count_key$count);
 
   }


Add this code to your [b]single.php file



[/b]

PHP Code:
<?php setPostViews(get_the_ID()); ?>



Add this code for display post counter

PHP Code:
<?php echo getPostViews(get_the_ID()); ?>
To Purchase Credit Click here , For how to make money on Sologet forum Click here 

HIRE ME FOR WEBSITE DESIGNING US THE PM BUTTON TO SEND ME MESSAGE

There is love in sharing
#2
if you are having any issues drop a comment
To Purchase Credit Click here , For how to make money on Sologet forum Click here 

HIRE ME FOR WEBSITE DESIGNING US THE PM BUTTON TO SEND ME MESSAGE

There is love in sharing
#3
where am to paste the display post counter
#4
Sir kingsolomon pls where is Display post counter in CSS dashboard?
#5
(04-27-2019, 10:38 PM)Obasi Wrote: Sir kingsolomon pls where is Display post counter in CSS dashboard?

Add it any where in the post where u want to display the view
To Purchase Credit Click here , For how to make money on Sologet forum Click here 

HIRE ME FOR WEBSITE DESIGNING US THE PM BUTTON TO SEND ME MESSAGE

There is love in sharing
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  Problems with seekhype theme Frizzy 0 85 04-02-2019, 12:12 PM
Last Post: Frizzy
  HOW TO Set mp3 tagger for wordpress djdozic 2 512 02-25-2019, 07:26 PM
Last Post: Kingsolomon
  HOW TO How to Fix the 502 Bad Gateway Error in WordPress khodex 1 299 01-09-2019, 07:48 AM
Last Post: Kingsolomon
  MUST READ 4 Ways To Remove Category from WordPress URLs Kingsolomon 1 379 12-18-2018, 10:10 AM
Last Post: Kingsolomon
  TIPS How to login and manual installation of wordpress aceboy 1 348 11-25-2018, 07:42 PM
Last Post: pola

Forum Jump:


Users browsing this thread:
1 Guest(s)

How To Show WordPress Post View Count Without A Plugin00