Advertisement
Guest User

Untitled

a guest
Mar 30th, 2012
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.56 KB | None | 0 0
  1. In functions.php:
  2.  
  3. //total site post count
  4. function post_count() {
  5.     global $wpdb;
  6.     if ( false === ( $cached_post_count = get_transient( 'cached_post_count' ) ) ) {
  7.         // It wasn't there, so regenerate the data and save the transient
  8.         $cached_post_count = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->posts . ' WHERE post_status = "publish" AND post_type = "post"');
  9.         set_transient( 'cached_post_count', $cached_post_count, 60*60*24 );
  10.     }
  11.     return $cached_post_count;
  12. }
  13.  
  14. Then display it anywhere in your theme:
  15.  
  16. <?php echo get_transient(cached_post_count); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement