Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: None  |  size: 0.73 KB  |  hits: 6  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?
  2. function tb_post_viewed( $post_id = null ) {
  3.  
  4.         // Get the current user.
  5.         global $current_user;
  6.         get_currentuserinfo();
  7.        
  8.         if ($post_id)
  9.                 $post = get_post($post_id);
  10.         else
  11.                 global $post;
  12.  
  13.         if ( ( $current_user->ID != $post->post_author ) && ( get_userdata( $current_user->ID )->user_level != 10 ) ) {
  14.                 $views = get_post_meta($post->ID, 'tb_views_count', true);
  15.                 if ( $views == null || $views == 0 || $views == '' )
  16.                         $views = 1;
  17.                 else
  18.                         // Increment the views variable.
  19.                         $views = intval( $views ) + 1;
  20.  
  21.                 // Save the new views value to the DB.
  22.                 echo 'You are not the author of this post or an admin';
  23.                 update_post_meta($post->ID, 'tb_views_count', $views);
  24.                
  25.         }
  26.  
  27.         echo tb_post_views( $post->ID );
  28. }