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 Mark Forums Read
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 05-17-2013, 01:14 AM   #1
madtwin
Confirmed User
 
Industry Role:
Join Date: Aug 2009
Posts: 274
How-to: Random post order [WP]

I need to randomize all posts on my WP tube, but like every 1-2 days.

I'm not talking about adding just '&orderby=rand' parameter to the query, it shuffles posts with every page visit/reload and makes some videos appear on page1 and 2...


Anyone?

madtwin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-17-2013, 01:52 AM   #2
harvey
Confirmed User
 
harvey's Avatar
 
Industry Role:
Join Date: Jul 2001
Location: 127.0.0.1
Posts: 9,266
http://codex.wordpress.org/Transients_API
__________________
This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth
harvey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-17-2013, 01:59 AM   #3
harvey
Confirmed User
 
harvey's Avatar
 
Industry Role:
Join Date: Jul 2001
Location: 127.0.0.1
Posts: 9,266
optionally, you can use a seed as an argument and store it as a variable so pagination will get the see and go from there. This is a great way to achieve what you're looking for, but I think it won't work well if you're using cache plugins (well, it will work but the purpose of cache plugins would be defeated)

edit: sorry, now I see you want this to change every couple days, not per session, so just go with Transients API, it's done for this exact purpose
__________________
This post is endorsed by CIA, KGB, MI6, the Mafia, Illuminati, Kim Jong Il, Worldwide Ninjas Association, Klingon Empire and lolcats. Don't mess around with it, just accept it and embrace the truth

Last edited by harvey; 05-17-2013 at 02:00 AM..
harvey is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-17-2013, 03:27 AM   #4
madtwin
Confirmed User
 
Industry Role:
Join Date: Aug 2009
Posts: 274
Thanks, that Transients API does exactly what I need


For those interested in this - How do I create a random post that will last for a day ( not tested )
madtwin is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-17-2013, 08:50 AM   #5
madtwin
Confirmed User
 
Industry Role:
Join Date: Aug 2009
Posts: 274
Shit... I can't get it work

I have standard query on index.php like this:

Quote:
<?php if(have_posts()) { ?>

<?php while (have_posts()) : the_post(); ?>

<div class="post" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_titile(); ?></a>
</div>

<?php endwhile; ?>
So where goes all the Transients API stuff? Something like this?

Quote:
<?php
// Get any existing copy of our transient data
if ( false === ( $special_query_results = get_transient( 'special_query_results' ) ) ) {
// It wasn't there, so regenerate the data and save the transient
$randargs = array('orderby' => 'rand', 'numberposts' => 10);
$special_query_results = get_posts($randargs);
set_transient( 'special_query_results', $special_query_results, 60*60*12 );
}

// Use the data like you would have normally...
$randomposts = get_transient( 'special_query_results' );

global $post;
foreach( $randomposts as $post ) : setup_postdata($post); ?>

<div class="post" id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_titile(); ?></a>
</div>

<?php endforeach; ?>
When using this code I get blank page...

madtwin 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
Thread Tools



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.