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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 06-04-2013, 04:45 AM   #1
mineistaken
See signature :)
 
mineistaken's Avatar
 
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?
mineistaken is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 12:22 PM   #2
mineistaken
See signature :)
 
mineistaken's Avatar
 
Industry Role:
Join Date: Apr 2007
Location: ICQ 363 097 773
Posts: 29,656
any WP guru's ?
mineistaken is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 12:38 PM   #3
alcstrategy
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>

Last edited by alcstrategy; 06-04-2013 at 12:40 PM..
alcstrategy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 12:48 PM   #4
mineistaken
See signature :)
 
mineistaken's Avatar
 
Industry Role:
Join Date: Apr 2007
Location: ICQ 363 097 773
Posts: 29,656
Thanks. Would this ^ display random posts from all categories combined?
mineistaken is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 12:53 PM   #5
alcstrategy
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
alcstrategy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 01:02 PM   #6
mineistaken
See signature :)
 
mineistaken's Avatar
 
Industry Role:
Join Date: Apr 2007
Location: ICQ 363 097 773
Posts: 29,656
Quote:
Originally Posted by alcstrategy View Post
i believe it will query posts from any category if that's what you mean
you can set categories with the "category" param
To be clear, I mean from "all" categories.
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.
mineistaken is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 01:04 PM   #7
Dankasaur
So Fucking Fossilized
 
Industry Role:
Join Date: Sep 2011
Posts: 1,432
Quote:
Originally Posted by mineistaken View Post
To be clear, I mean from "all" categories.
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.
You'd have to loop through all your categories and pull them, and then pull 3 random posts from each category.
Dankasaur is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 01:05 PM   #8
EddyTheDog
Just Doing My Own Thing
 
EddyTheDog's Avatar
 
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
Quote:
Originally Posted by mineistaken View Post
To be clear, I mean from "all" categories.
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.

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
EddyTheDog is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 01:07 PM   #9
EddyTheDog
Just Doing My Own Thing
 
EddyTheDog's Avatar
 
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,038
Quote:
Originally Posted by Dankasaur View Post
You'd have to loop through all your categories and pull them, and then pull 3 random posts from each category.
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
EddyTheDog is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 01:10 PM   #10
mineistaken
See signature :)
 
mineistaken's Avatar
 
Industry Role:
Join Date: Apr 2007
Location: ICQ 363 097 773
Posts: 29,656
Quote:
Originally Posted by EddyTheDog View Post
Wouldn't it use all posts and then randomize them?.....
Thats what I need. Pull all posts from all categories and display them all at random order
mineistaken is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 01:13 PM   #11
alcstrategy
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

Last edited by alcstrategy; 06-04-2013 at 01:15 PM.. Reason: was new reply on refresh
alcstrategy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 01:29 PM   #12
Dankasaur
So Fucking Fossilized
 
Industry Role:
Join Date: Sep 2011
Posts: 1,432
Quote:
Originally Posted by EddyTheDog View Post
Wouldn't it use all posts and then randomize them?.....
No because you'd pass the category off to the query for posts and it'd only pull random ones in that category.
Dankasaur is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-04-2013, 02:01 PM   #13
BSleazy
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
BSleazy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.