Title: random quote from posts
Last modified: August 19, 2016

---

# random quote from posts

 *  Resolved [indiaberry](https://wordpress.org/support/users/indiaberry/)
 * (@indiaberry)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/random-quote-from-posts/)
 * I would like my blog set up to where I could have random quote from the post 
   show in the side bar. Like I could put this <quote something> test </quote something
   > around the partial text in the post, where I want to quote in the sidebar.

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

 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/random-quote-from-posts/#post-739665)
 * That might be a bit hard to do. I would suggest using custom fields for this.
   For example, if you want to show a quote from your posts, you’d need to set up
   a custom field ** Key** titled “Quote.” Then, give it a ** Value** of your quoted
   text.
 * So, something like this:
 *     ```
       <?php
       if(have_posts()) :
       	while(have_posts()) :
       		the_post();
       		$quote = get_post_custom_values($key = 'Quote');
       		echo $quote[0];
       	endwhile;
       endif;
       ?>
       ```
   
 * You could add `query_posts('showposts=5');` at the top of that to show your last
   5 posts.
 * This is totally untested, but it should be something fun to play around with.
   I do have a [ tutorial series on using custom fields](http://justintadlock.com/archives/2007/10/24/using-wordpress-custom-fields-introduction)
   if you want to learn more about them.
 * **[Edit]**
    Of course, it might be a bit easier just to use the Optional Excerpts,
   and display it with `the_excerpt()`.
 * **[Update]**
    Okay, it works. I just tested the code above.
 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/random-quote-from-posts/#post-739667)
 * I suppose, if you wanted to get more complicated, you could add several instances
   of the custom field ** Key** titled “Quote” with different quoted pieces of text.
   Then, you’d have to use something like this:
 *     ```
       <?php
       if(have_posts()) :
       	while(have_posts()) :
       		the_post();
       		$quote = get_post_custom_values($key = 'Quote');
       		$randomquote = rand(0,count($quote)-1);
       		$quote = $quote[$randomquote];
       		echo $quote;
       	endwhile;
       endif;
       ?>
       ```
   
 *  Thread Starter [indiaberry](https://wordpress.org/support/users/indiaberry/)
 * (@indiaberry)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/random-quote-from-posts/#post-739757)
 * If I want to show the quote from the posts in the side bar, or in the header,
   what do I put in the sidebar or header?
 *  [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * (@greenshady)
 * [18 years, 2 months ago](https://wordpress.org/support/topic/random-quote-from-posts/#post-739857)
 * The code I posted.

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

The topic ‘random quote from posts’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [Justin Tadlock](https://wordpress.org/support/users/greenshady/)
 * Last activity: [18 years, 2 months ago](https://wordpress.org/support/topic/random-quote-from-posts/#post-739857)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
