Title: random category list
Last modified: August 19, 2016

---

# random category list

 *  Resolved [asifg123](https://wordpress.org/support/users/asifg123/)
 * (@asifg123)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/random-category-list/)
 * Hi
 * is there any way that i can show random category list in my post bottom side
 * What do I do?
 * thanks

Viewing 9 replies - 1 through 9 (of 9 total)

 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/random-category-list/#post-1547299)
 *     ```
       <?php
       //display random sorted list of terms in a given taxonomy
       $taxonomy = 'category';
       $terms = get_terms($taxonomy);
       shuffle ($terms);
       //echo 'shuffled';
       if ($terms) {
       	foreach($terms as $term) {
       		echo '<p><a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a></p> ';
       	}
       }
       ?>
       ```
   
 *  Thread Starter [asifg123](https://wordpress.org/support/users/asifg123/)
 * (@asifg123)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/random-category-list/#post-1547370)
 * thanks MichaelH 🙂
 * but how can i limit the category list because this code show all category i want
   show only 10 category .
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/random-category-list/#post-1547374)
 * Put a counter in the foreach loop.
 *  Thread Starter [asifg123](https://wordpress.org/support/users/asifg123/)
 * (@asifg123)
 * [15 years, 11 months ago](https://wordpress.org/support/topic/random-category-list/#post-1547383)
 * please give me some more detail because i am newbie in wordpress 🙂
 * thanks
 *  Thread Starter [asifg123](https://wordpress.org/support/users/asifg123/)
 * (@asifg123)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/random-category-list/#post-1547510)
 * hello MichaelH
 * some counter code i searched on google but thet can’t work 🙁
    please help
 *  [MichaelH](https://wordpress.org/support/users/michaelh/)
 * (@michaelh)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/random-category-list/#post-1547513)
 *     ```
       <?php
       //display random sorted list of terms in a given taxonomy
       $counter = 0;
       $max = 5; //number of categories to display
       $taxonomy = 'category';
       $terms = get_terms($taxonomy);
       shuffle ($terms);
       //echo 'shuffled';
       if ($terms) {
       	foreach($terms as $term) {
       		$counter++;
       		if ($counter <= $max) {
       	  	echo '<p><a href="' . get_category_link( $term->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $term->name ) . '" ' . '>' . $term->name.'</a></p> ';
       	 	}
       	}
       }
       ?>
       ```
   
 *  Thread Starter [asifg123](https://wordpress.org/support/users/asifg123/)
 * (@asifg123)
 * [15 years, 10 months ago](https://wordpress.org/support/topic/random-category-list/#post-1547521)
 * thank you very much Michael 🙂
 *  [RachelNabors](https://wordpress.org/support/users/rachelnabors/)
 * (@rachelnabors)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/random-category-list/#post-1547795)
 * I have problems getting this to work with custom taxonomies. The permalink won’t
   print, and if I change it to “get_term_link” it returns an error. Any help?
 *  [RachelNabors](https://wordpress.org/support/users/rachelnabors/)
 * (@rachelnabors)
 * [15 years, 1 month ago](https://wordpress.org/support/topic/random-category-list/#post-1547796)
 * Got it! Swap out `get_category_link( $term->term_id )` for `get_term_link( $term,
   $taxonomy )`

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘random category list’ is closed to new replies.

## Tags

 * [meh_code](https://wordpress.org/support/topic-tag/meh_code/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 9 replies
 * 3 participants
 * Last reply from: [RachelNabors](https://wordpress.org/support/users/rachelnabors/)
 * Last activity: [15 years, 1 month ago](https://wordpress.org/support/topic/random-category-list/#post-1547796)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
