A small code but fun for wordpress site ;)

by BaMoon
7 replies
  • WEB DESIGN
  • |
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
#code #fun #small #wordpress
  • Profile picture of the author Walter White
    Thanks what a nice contribution!
    {{ DiscussionBoard.errors[4031526].message }}
  • Profile picture of the author bappy007
    Really nice. Thanks.
    {{ DiscussionBoard.errors[4031707].message }}
  • Profile picture of the author BaMoon
    thanks for your reply
    If you have any question about WP, please show and I will try to help you
    {{ DiscussionBoard.errors[4036213].message }}
  • Profile picture of the author alanabowe
    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!
    Signature
    {{ DiscussionBoard.errors[4036370].message }}
  • Profile picture of the author BaMoon
    Yes, you are welcome
    {{ DiscussionBoard.errors[4043345].message }}
  • Profile picture of the author Walter White
    do you have more snippets like these ?
    {{ DiscussionBoard.errors[4051248].message }}
    • Profile picture of the author BaMoon
      Originally Posted by Walter White View Post

      do you have more snippets like these ?
      yes, I will post soon
      {{ DiscussionBoard.errors[4097274].message }}

Trending Topics