List of random posts
I want to list 10 random posts on my wordpress blog. I’ve used this code:
<ul> <?php $args = array( 'numberposts' => 10, 'orderby' => 'rand' ); $rand_posts = get_posts( $args ); foreach( $rand_posts as $post ) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php endforeach; ?> </ul>
However order by RAND() is evil, it’s very not optimal for database.
So I must replace this piece of code with another. Can someone help me, I don’t program in php.
In the above link it is said that getting random record is not a problem. Can someone write how to repeat this operation 10 times (it’s not a problem for me if some post will be get more than 1 time).
Thanks in advance for your help.
- The topic ‘List of random posts’ is closed to new replies.