![]() |
wordpress developers - advice on how to random posts from all categories
How to random display posts from all categories, most importantly when index.php is not a home page, since home page is static page.
Any solution? |
any WP guru's ? :winkwink:
|
as with anything there's many ways to skin a cat, but there's an example in wordpress docs here: http://codex.wordpress.org/Template_Tags/get_posts
numberposts is the number of posts you want orderby is rand which is equiv to mysql rand() which is random num the docs show other parameters you can use also i guess you could put this in page.php, although I guess it depends where you want it, etc, but i just posted general example <ul> <?php $args = array( 'numberposts' => 5, '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> |
Thanks. Would this ^ display random posts from all categories combined?
|
i believe it will query posts from any category if that's what you mean
you can set categories with the "category" param |
Quote:
Lets say there are 3 categories - blondes, brunettes and redheads. I want to have page (not home page) where all posts from all 3 categories would be displayed at random order. |
Quote:
|
Quote:
I am not saying that code would work - I haven't tried it - If it does then it would show from all cats... |
Quote:
|
Quote:
|
it queries all posts and returns random order but will limit to 5 because of the numberposts paramater
|
Quote:
|
You should be able to do something like this
Code:
<?php $posts = get_posts('orderby=rand&numberposts=10'); foreach($posts as $post) { ?> |
All times are GMT -7. The time now is 07:12 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc