Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- In functions.php:
- //total site post count
- function post_count() {
- global $wpdb;
- if ( false === ( $cached_post_count = get_transient( 'cached_post_count' ) ) ) {
- // It wasn't there, so regenerate the data and save the transient
- $cached_post_count = $wpdb->get_var('SELECT COUNT(*) FROM ' . $wpdb->posts . ' WHERE post_status = "publish" AND post_type = "post"');
- set_transient( 'cached_post_count', $cached_post_count, 60*60*24 );
- }
- return $cached_post_count;
- }
- Then display it anywhere in your theme:
- <?php echo get_transient(cached_post_count); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement