WordPress.org

Ready to get started?Download WordPress

Forums

Taxonomy Images
Display 4 random tags with images (1 post)

  1. spexer
    Member
    Posted 1 year ago #

    Hello, first I like to thank you guys for a very nice plugin!

    Ok here we go. I would like to get 4 random tags to show on my homepage. But when I use my code all the tags show up. It seems like my count function is not working neither the shuffle .

    Please, can someone give me some pointers?

    The code got so far inside public-filters is this:

    shuffle($terms);
    $max_loop=1; //This is the desired value of Looping
    $count = 0; //First we set the count to be zeo
    	foreach( $terms as $term ) {
    
    $count++; //Increase the value of the count by 1
    if($count==$max_loop) { break; //Break the loop is count is equal to the max_loo
    	}
    		if ( ! isset( $term->image_id ) ) {
    			continue;
    		}
    		$image = wp_get_attachment_image( $term->image_id, $args['image_size'] );
    		if ( ! empty( $image ) ) {
    			$output .= $args['before_image'] . '<li><p style="text-align: center;"><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $image .'</a><br><a href="' . esc_url( get_term_link( $term, $term->taxonomy ) ) . '">' . $term->name . '</a></p></li>' . $args['after_image'] ;
    		}
    	}
    
    	if ( ! empty( $output ) ) {
    		return $args['before'] . $output . $args['after'];
    	}
    	return '';
    }

    http://wordpress.org/extend/plugins/taxonomy-images/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.