Forums

Show post in random order (4 posts)

  1. euforico
    Member
    Posted 4 months ago #

    Hi

    I use the next code for show my post

    <?php $my_query = new WP_Query('cat=9&showposts=10'); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php the_excerpt(''); ?>
    <?php endwhile; ?>

    Show the items of the category 9 in order for date.
    How can show the post in random order?

    thanks

  2. ryans149
    Member
    Posted 4 months ago #

  3. euforico
    Member
    Posted 4 months ago #

    Both plugins working, but isn`t what i need because:

    Random post plugin and post options: working only for one function, i can call only a one random post and i need five similar random post

    Do you know about another plugin? or give a random order with my function?

  4. Niconectado
    Member
    Posted 1 month ago #

    hola euforico,
    to show any random posts from a single category you should specify this string to the "query_post" function (instead of using "wp_query"):

    // show me 10 random posts from category ID=9
    
    <?php $my_query = new query_posts("cat=9&showposts=10&orderby=rand"); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php the_excerpt(''); ?>
    <?php endwhile; ?>
    
    // show me 12 random posts from categories ID's 1,2,3
    
    <?php $my_query = new query_posts("cat=1,2,3&showposts=12&orderby=rand"); ?>
    <?php while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
    <?php the_title(); ?>
    <?php the_content(); ?>
    <?php the_excerpt(''); ?>
    <?php endwhile; ?>

    I also recommend you to pass by Anieto2K's blog, he has interesting stuff about controlling this function.

    just worked for me! so glad i've found this other post with the missing parameter.

Reply

You must log in to post.

About this Topic