WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: TBTestimonials] Random testimonial from a category

[Resolved] [Plugin: TBTestimonials] Random testimonial from a category

  • On my to-do list was to add a hack in a shortcode option to select from a category – when I sat down to write it, there was an update!!

    But it only allows ALL testimonials from a category. This is unnecessarily restrictive – a single random testimonial from a category is a useful use-case (and the one I needed!)

    The easiest mod to allow this is to simply append a case to the handlers for various shortcode cases (in shortcode()):

    else if( ! is_null( $id ) && ! is_null( $cat ) && strtolower( $id ) == 'random' || strtolower( $id ) == 'rand' ) # random from category
            {
                $q = new WP_Query( array(
                	'post_type' => 'testimonial',
                	'post_status' => 'publish',
                	'orderby' => 'rand',
                	'posts_per_page' => 1,
                	'testimonial_category' => $cat
                ) );
    
                if( $q->have_posts() )
                {
                    $return = '<div id="tbtestimonial-listing">';
                    while( $q->have_posts() )
                    {
                        $q->the_post();
                        isset( $this->settings['use_template_api'] ) ?
                            $return .= $this->prepare_testimonial( is_null( $template ) ? 'listing' : $template ) :
                            $return .= $this->deprecated__prepare_testimonial( 'shortcode-all' );
                    }
                    wp_reset_query();
                    return $return . '</div>';
                }
                else
                    return;
            }

    Although there are other ways that won’t duplicate all that code 😉

    This is tested and works.

    Thanks so much for a great plugin – really is done the way it ought to be. hope this is helpful.

    http://wordpress.org/extend/plugins/tb-testimonials/

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘[Resolved] [Plugin: TBTestimonials] Random testimonial from a category’ is closed to new replies.