A small code but fun for wordpress site ;)

by 7 replies
8
Put this code anywhere on your wordpress page


Code:
<?php
function Statistic($id)
{ global $wpdb;
 if($id==0){
 $num_posts = $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
if ($num_posts > 0) $num_posts = number_format($num_posts);
 echo  $num_posts;
 return $num_posts;
 }
 if($id==1)
 {
 $num_comments = $wpdb->get_var("SELECT COUNT(comment_ID) FROM $wpdb->comments WHERE comment_approved = '1′");
if ($num_comments > 0) $num_comments = number_format($num_comments);
  echo  $num_comments;
  return $num_comments;
 }
 if($id==2)
 {$num_played = $wpdb->get_var("SELECT SUM( meta_value ) FROM  $wpdb->postmeta WHERE meta_key =  'views'");
  if ($num_played > 0) $num_played = number_format($num_played);
  echo $num_played;
  return $num_played;
 }
}
?>
<b> Total: <?php Statistic(0);?> game. <?php Statistic(1);?> Comments. <?php Statistic(2);?> played on gameonline9.com</b>
Demo : Let's join Gameonline9 at my signature
#website design #code #fun #small #wordpress
  • Thanks what a nice contribution!
  • Really nice. Thanks.
  • thanks for your reply
    If you have any question about WP, please show and I will try to help you
  • Great! I am still a novice to wordpress, and I believe I can learn a lot of things from here. I will surely visit more often for more inputs. Thanks!
  • Yes, you are welcome
  • do you have more snippets like these ?
    • [1] reply
    • yes, I will post soon

Next Topics on Trending Feed