WordPress.org

Ready to get started?Download WordPress

Forums

show random posts in this code (3 posts)

  1. theotherlebowski
    Member
    Posted 3 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:

    <ul>
    <?php
    	$my_query = new WP_Query('showposts=6');
    	while ($my_query->have_posts()) : $my_query->the_post();$do_not_duplicate = $post->ID;
    ?>
    <li>
    
    	<?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 } ?>
    
    </li>
    
    <?php endwhile; ?>
    </ul>

    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. alchymyth
    Forum Moderator
    Posted 3 years ago #

    http://codex.wordpress.org/Function_Reference/WP_Query#Order_.26_Orderby_Parameters

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

  3. theotherlebowski
    Member
    Posted 3 years ago #

    you legend :D just the ticket. thanks dude.

Topic Closed

This topic has been closed to new replies.

About this Topic