![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
See signature :)
Industry Role:
Join Date: Apr 2007
Location: ICQ 363 097 773
Posts: 29,656
|
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? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
See signature :)
Industry Role:
Join Date: Apr 2007
Location: ICQ 363 097 773
Posts: 29,656
|
any WP guru's ?
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: May 2012
Posts: 124
|
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> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
See signature :)
Industry Role:
Join Date: Apr 2007
Location: ICQ 363 097 773
Posts: 29,656
|
Thanks. Would this ^ display random posts from all categories combined?
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Industry Role:
Join Date: May 2012
Posts: 124
|
i believe it will query posts from any category if that's what you mean
you can set categories with the "category" param |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 | |
See signature :)
Industry Role:
Join Date: Apr 2007
Location: ICQ 363 097 773
Posts: 29,656
|
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. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
So Fucking Fossilized
Industry Role:
Join Date: Sep 2011
Posts: 1,432
|
You'd have to loop through all your categories and pull them, and then pull 3 random posts from each category.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Just Doing My Own Thing
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
|
Quote:
I am not saying that code would work - I haven't tried it - If it does then it would show from all cats...
__________________
- Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Just Doing My Own Thing
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
|
Wouldn't it use all posts and then randomize them?.....
__________________
- Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
See signature :)
Industry Role:
Join Date: Apr 2007
Location: ICQ 363 097 773
Posts: 29,656
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Confirmed User
Industry Role:
Join Date: May 2012
Posts: 124
|
it queries all posts and returns random order but will limit to 5 because of the numberposts paramater
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
So Fucking Fossilized
Industry Role:
Join Date: Sep 2011
Posts: 1,432
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 |
Confirmed User
Industry Role:
Join Date: Aug 2002
Location: USA
Posts: 6,721
|
You should be able to do something like this
Code:
<?php $posts = get_posts('orderby=rand&numberposts=10'); foreach($posts as $post) { ?>
__________________
icq 156131086 |
![]() |
![]() ![]() ![]() ![]() ![]() |