How to display random posts? (7 posts)

  1. isaacnb
    Posted 8 years ago #

    If been using this Mimbo theme, and in the index page it shows some posts using:

    $display_categories = array(5,19);
    foreach ($display_categories as $category) { ?>

    There you choose witch categories to display.

    I want to know if it's possible to display random posts insted of fixed posts.

    Thank you.

  2. MichaelH
    Posted 8 years ago #

    You might need to paste the complete contents of index.php in at wordpress.pastebin.ca and report the link back here.

    In the meantime, http://wordpress.org/search/display+random+posts?forums=1

  3. spoole
    Posted 8 years ago #

    Or, via a magical 2 seconds with google, you could always go straight to the Random Posts plugin. ;)

  4. Tsoftwarez
    Posted 8 years ago #

    Alternately you could try The Randomizer Plugin.

    The Randomizer

  5. smsu
    Posted 8 years ago #

    I need to display a random post from a particular category on a page not in the loop, is this possible?

    Can you point me in the right direction please

    The page is in the theme root and is basically a static (home)page with a latest posts item which works fine, what I need to do is have a random post appear from a particular category (i.e. a random testimonial exerpt)

    Thanks in advance

  6. nickolasalvarado
    Posted 8 years ago #

    check the wordpress docs, theres lots of ways to do it.

    You would need to edit your static page so have something like this...

    <?php $yourquery = new WP_Query();
    $yourquery->posts('cat=(whatever number category youre using)&order=RAND');
    while($yourquery->have_posts()) : $yourquery->the_post(); setup_postdata($yourquery); ?>


    <?php endwhile; ?>

  7. smsu
    Posted 8 years ago #

    Thank you for that

    I'm still a bit lost as I get an undefined call to function error.

    Fatal error: Call to undefined function: posts() in /home/sites/public_html/wp-content/themes/wpremix/tpl_Home1.php on line 29

    I'm using WP2.5.1, and have spent hours reading the docs but its a bit above me to be honest.

    I'd appreciate a simple fix but I'm sure its not that easy

    Thanks in advance

Topic Closed

This topic has been closed to new replies.

About this Topic