• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

Creating a Random Page

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › Design Tips and Tricks › Creating a Random Page

This topic is: not resolved
  • This topic has 6 replies, 2 voices, and was last updated 12 years, 1 month ago by mrhiking.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • January 12, 2014 at 10:49 pm #84910
    mrhiking
    Member

    I'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!
    - Mike

    January 13, 2014 at 5:22 am #84939
    Davinder Singh Kainth
    Member

    Why 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 Themes

    January 13, 2014 at 7:19 am #84944
    mrhiking
    Member

    Hi 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 #85124
    Davinder Singh Kainth
    Member

    Strange, 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 Themes

    January 14, 2014 at 11:30 am #85168
    mrhiking
    Member

    Sweet! That worked.

    What would I need to do if I wanted to make that a button?

    January 15, 2014 at 12:48 am #85291
    Davinder Singh Kainth
    Member

    You 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 Themes

    January 15, 2014 at 12:24 pm #85369
    mrhiking
    Member

    Thanks!

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘Design Tips and Tricks’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble