Community Forums › Forums › Archived Forums › Design Tips and Tricks › Creating a Random Page
- This topic has 6 replies, 2 voices, and was last updated 12 years, 1 month ago by
mrhiking.
-
AuthorPosts
-
January 12, 2014 at 10:49 pm #84910
mrhiking
MemberI'm trying to create a page called 'Random' that displays 1 post randomly.
I found this code:
<?php query_posts(array('orderby' => 'rand', 'showposts' => 1)); if (have_posts()) : while (have_posts()) : the_post(); ?> <h1><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h1> <?php the_content(); ?> <?php endwhile; endif; ?>I would like the 'Random' page to have the same header, sidebar, footer as the rest of my site.
I know I need to build a custom page template. But, I how do I do this?
Thanks!
- MikeJanuary 13, 2014 at 5:22 am #84939Davinder Singh Kainth
MemberWhy don't you use random post plugin for this functionality - http://wordpress.org/plugins/random-post-link/
Sunshine PRO genesis theme
Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis ThemesJanuary 13, 2014 at 7:19 am #84944mrhiking
MemberHi Davinder -
I tried that with both Random Redirect plugins and both caused fatal errors. I'm using the most recent WordPress/Genesis. I don't think either are compatible.
January 14, 2014 at 6:08 am #85124Davinder Singh Kainth
MemberStrange, one of my client is using random-post plugin fine in header area (http://www.stuffselect.com/ - website is using custom made theme from sample genesis theme html5)
1. Install plugin
2. Drag PHP code widget to area of your choice. Paste this code into it<?php random_post_link('Click for Random Surprise !'); ?>
To get php code widget thing in your widgets section, you should install small plugin as explained here: http://www.basicwp.com/run-php-code-wordpress-text-widget/
Sunshine PRO genesis theme
Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis ThemesJanuary 14, 2014 at 11:30 am #85168mrhiking
MemberSweet! That worked.
What would I need to do if I wanted to make that a button?
January 15, 2014 at 12:48 am #85291Davinder Singh Kainth
MemberYou can easily convert into button by wrapping php code in a css class.
Replace code in php code with this:
<div class="randompost"><?php random_post_link('Click for Random Surprise !'); ?></div>
Then add following code to style.css file (play around with colors as per requirement).
.randompost {
font-size:14px;
line-height:1.2;
text-align:center;
float:center;
margin:28px 0 -28px 80px;
font-weight:bold;
clear:both;}
.randompost a {
color:#c3151c;
background:#f8f7f7;
padding:8px 30px;
text-decoration:none;
border-radius:60px;
font-family: Lato, arial, sans-serif;
}.randompost a:hover {
color:#fff;
background:#c3151c;
}
Sunshine PRO genesis theme
Need Genesis help? Davinder @ iGuiding Media | My Blog | Fresh Genesis ThemesJanuary 15, 2014 at 12:24 pm #85369mrhiking
MemberThanks!
-
AuthorPosts
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.