show random posts in this code (3 posts)

  1. jack randall
    Posted 5 years ago #

    hello, i was wondering if any code gurus out there might be able to help: i've got client who's using a child of the Neptune theme on her site and she wants to have the recent posts sidebar doodah to show a random selction of posts (obviously i'll need to rename the doodah!) rather than the top 6 newest posts.

    this is the code that fetches and outputs:

    	$my_query = new WP_Query('showposts=6');
    	while ($my_query->have_posts()) : $my_query->the_post();$do_not_duplicate = $post->ID;
    	<?php if ( has_post_thumbnail() ) {?>
    	<a href="<?php the_permalink() ?>" title="Permanent Link to <?php the_title(); ?>">
    	<?php  the_post_thumbnail( 'neptune-minithumb', array('class' => 'custim3') );?></a>
    	<?php } else { ?>
    	<?php } ?>
    <?php endwhile; ?>

    i know there's a MySQL call for generating random results but my php coding chops aren't up to the job i'm afraid. can anyone see where if at all i can make changes to this code to make it show the random selection?

    the site in question is hierophant-nox.com if you want to take a look see the end results.

    big thanks in advance guys. :D

  2. Michael
    Forum Moderator
    Posted 5 years ago #


    $my_query = new WP_Query('posts_per_page=6&orderby=rand');

  3. jack randall
    Posted 5 years ago #

    you legend :D just the ticket. thanks dude.

Topic Closed

This topic has been closed to new replies.

About this Topic