Title: Random post link? HELP
Last modified: August 20, 2016

---

# Random post link? HELP

 *  [phattrance](https://wordpress.org/support/users/phattrance/)
 * (@phattrance)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/random-post-link-help/)
 * Is it possible to add a random post link in wordpress?
 * Go to this page: [http://funny-pictures-blog.com/2011/06/07/funny-pictures-bad-day-2/](http://funny-pictures-blog.com/2011/06/07/funny-pictures-bad-day-2/)
   below the image u can see the next and previous links, i want to have a link 
   in the middle were it says “Random post”. that link should randomly choose a 
   post and display it for the reader. is that possible to add?
 * i am using this code for the next and previous links:
 * <div class=”nav-box next” style=”float:right;”><h2>**<?php previous_post_link(‘%
   link’, ‘Next Post >>>’, false); ?>**</h2>
   </div> <div class=”nav-box next” style
   =”float:left;”><h2>**<?php next_post_link(‘%link’, ‘<<< Previous Post’, false);?
   >**</h2></div>

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

 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121096)
 * Try this:
 *     ```
       <div class="nav-box next" style="float:right;"><h2><?php previous_post_link('%link', 'Next Post >>>', false); ?></h2></div>
   
       <?php
       $random_post = get_posts('posts_per_page=1&orderby=rand');
       $link = '<a href="'.get_permalink($random_post[0]->ID).'" title="'.get_the_title($random_post[0]->ID).'">'.get_the_title($random_post[0]->ID).'</a>';
       ?>
       <div class="nav-box random" style="float:left;"><h2><?php echo $link; ?></h2></div> 
   
       </div> <div class="nav-box next" style="float:left;"><h2><?php next_post_link('%link', '<<< Previous Post', false); ?></h2></div>
       ```
   
 *  Thread Starter [phattrance](https://wordpress.org/support/users/phattrance/)
 * (@phattrance)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121101)
 * It looks like this now: [http://i.imgur.com/tAOs6.jpg](http://i.imgur.com/tAOs6.jpg)
 * i want the random post to be in the middle and also i dont want the links name
   to be the post title, just want it to be called “Random Post”
 * possible to fix this?
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121107)
 * Try it with this:
 *     ```
       <div class="nav-box next"><h2><?php next_post_link('%link', '<<< Previous Post', false); ?></h2></div> 
   
       <?php
       $random_post = get_posts('posts_per_page=1&orderby=rand');
       $link = '<a href="'.get_permalink($random_post[0]->ID).'" title="Random Post:'.get_the_title($random_post[0]->ID).'">Random Post</a>';
       ?>
       <div class="nav-box random" ><h2><?php echo $link; ?></h2></div> 
   
       <div class="nav-box previous"><h2><?php previous_post_link('%link', 'Next Post >>>', false); ?></h2></div>
       ```
   
 * and put this in your theme’s stylesheet (style.css?).
 *     ```
       div.nav-box {
       width: 32%;
       }
   
       div.nav-box.next, div.nav-box.random {
       float: left;
       }
   
       div.nav-box.previous {
       float: right;
       }
       ```
   
 *  Thread Starter [phattrance](https://wordpress.org/support/users/phattrance/)
 * (@phattrance)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121113)
 * Thank you, it works better now. i have one question tho! is it possible to move
   the “next post” more to the right? as you can see in this screenshot, theres 
   still a lot of available space to place the next page link. i would like to have
   the previous post as much to the left as possible, the random post in the middle
   and the next post as much to the right as possible.
 * > [View post on imgur.com](https://imgur.com/d3HjU)
 *  Moderator [keesiemeijer](https://wordpress.org/support/users/keesiemeijer/)
 * (@keesiemeijer)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121114)
 * Then I need a link to the page in question. I can only guess right now how your
   html structure and stylesheet rules are.
 *  Thread Starter [phattrance](https://wordpress.org/support/users/phattrance/)
 * (@phattrance)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121123)
 * here you are [http://funny-pictures-blog.com/2011/06/07/spongebob-funny/](http://funny-pictures-blog.com/2011/06/07/spongebob-funny/)
 *  Thread Starter [phattrance](https://wordpress.org/support/users/phattrance/)
 * (@phattrance)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121249)
 * Hi!
 * did you have any luck fixing the bug?
 *  [wingvictory](https://wordpress.org/support/users/wingvictory/)
 * (@wingvictory)
 * [14 years, 10 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121424)
 * hi I am trying to do this too. i am new so people bare with me.
 * I’ve been trying to post the Code in single.php (both for the next/previous/random
   buttons) nothing is working. here is my coding without the button text…where 
   do I paste the code to make the new links?
 * > <?php get_header(); ?>
   > <!– ///////////////////////////////////////////////////////////////////////–
   > >
   >  <!– // // –> <!– ///////////////////////////////////////////////////////////////////////–
   > > <div id=”content_container”>
   >  <div id=”content_wrapper”>
   >  <?php include “templates/”.get_single_cat_type().”/”.get_cat_single_template().”.
   > php”; ?>
   >  </div><!– END div#content_wrapper –>
   >  </div><!– END div#content_container –>
   >  <?php get_footer(); ?>
 *  [angelforever123](https://wordpress.org/support/users/angelforever123/)
 * (@angelforever123)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121490)
 * Hi keesiemeijer, Is there a way to pull random posts from a particular categories?
 * Thanks
 *  [angelforever123](https://wordpress.org/support/users/angelforever123/)
 * (@angelforever123)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121491)
 * alright i got it 🙂 i knw that was quick 😛 may be i asked before i tried 😀

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

The topic ‘Random post link? HELP’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 4 participants
 * Last reply from: [angelforever123](https://wordpress.org/support/users/angelforever123/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/random-post-link-help/#post-2121491)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
