
Untitled
By: a guest on
Aug 10th, 2012 | syntax:
None | size: 0.73 KB | hits: 6 | expires: Never
<?
function tb_post_viewed( $post_id = null ) {
// Get the current user.
global $current_user;
get_currentuserinfo();
if ($post_id)
$post = get_post($post_id);
else
global $post;
if ( ( $current_user->ID != $post->post_author ) && ( get_userdata( $current_user->ID )->user_level != 10 ) ) {
$views = get_post_meta($post->ID, 'tb_views_count', true);
if ( $views == null || $views == 0 || $views == '' )
$views = 1;
else
// Increment the views variable.
$views = intval( $views ) + 1;
// Save the new views value to the DB.
echo 'You are not the author of this post or an admin';
update_post_meta($post->ID, 'tb_views_count', $views);
}
echo tb_post_views( $post->ID );
}