Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * A simple shortcode to display the number of published podcasts on your site. Uses the `podcast` post type.
- *
- * Use the minus attribute to subtract the specified number from the final total.
- * Useful if you want to build a little suspense and create something like: We have 100+ podcasts!
- * (when in reality you have 101 podcasts)
- * [podcast-count minus="1"]
- *
- * Requires PHP 5.3+ for anonymous functions. Rewrite it if you want. You have been warned!
- */
- add_action('init', function(){
- add_shortcode('podcast-count', function( $atts ){
- $attributes = shortcode_atts( array(
- 'minus' => 'false',
- 'add' => 'false'
- ), $atts );
- // Store the query result. Change the post type slug if yours is different.
- $count = wp_count_posts( 'podcast' );
- // get published podcasts
- $podcasts = isset( $count->publish ) ? $count->publish : 0;
- // Subtract if necessary
- if ( $attributes['minus'] !== "false" ){
- $podcasts = $podcasts - intval($attributes['minus']);
- }
- // Add if necessary
- if ( $attributes['add'] !== "false" ){
- $podcasts = $podcasts + intval($attributes['add']);
- }
- return intval($podcasts);
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement