I'm using Wordpress and a plugin called Testimonials Widget which creates a post type of its own for rotating testimonials with testimonialswdiget_widget() or a list with testimonialswidget_list(). I don't have all my code yet because I can't even get this part to work yet --

<?php 
if ($all_the_tags);
$all_the_tags = get_the_tags();
foreach($all_the_tags as $this_tag) {
echo do_shortcode('[testimonialswidget_list  tags="<?php echo $this_tag->name; ?>" limit=2]');
 }
?> 

Currently that code is displaying every testimonial I currently have in the system (2) for as many times as there are tags on the post. If there are no tags, it doesn't display anything.

What I'm trying to do is display testimonials in the sidebar which share a tag with the current post. If I'm on a page, I would like to display all testimonials. I will change them all to the rotator type after, I'm using list as a debug. So I don't care if it shows the same testimonials twice or 3 times or 5 times, or if there's 25 tags so there's 25 testimonials. That doesn't matter (except when it comes to query loads, I get it, so perhaps an iteration limiter so it doesn't become 30?).

Anyone got any ideas?

Why is there a semi-colon at the end of the line your if statement is on?
Also your do_shortcode part doesn't seem to make sense. No reason to put <?php ?> in there. Try:

echo do_shortcode('[testimonialswidget_list tags="'.$this_tag->name.'" limit=2]');

Note I haven't tested and have never worked with this widget or tags in WP, but if your variables are correct that should fix some errors.

Thanks EvolutionFallen! I didn' t see this until now, but a new friend of mine helped get this one solved. Here's the final working code:

<?php 

global $post;
$all_the_tags = get_the_tags($post->ID);
foreach($all_the_tags as $this_tag) {
    $output = do_shortcode('[testimonialswidget_list tags="' . $this_tag->slug . '" limit=2]');
   if ( stripos( $output, 'no testimonials found') === false ) echo $output;
}
?> 
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.