View Single Post
Old 11-25-2010, 10:10 PM  
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,372
Quote:
Originally Posted by Highest Def View Post
I have searched high and low and keep finding the same 'random posts' widgets. I want to just shuffle every post and eliminate dates all together. It's a Wordpress tube site and every few days I add 20 or 30 clips from a new sponsor, but I don't want the videos clumped together by site like that so I have been adding them with my own random dates, but I'd rather just add them all and have Wordpress do the randomizing.
you could do something like this (very rough)

Code:
<?php 

// show 5 random posts, dont repeat the same posts for an hour

function fris_run_cookie($savecookieid) {

	setcookie("randompostsviewed", ''); //delete old ones
	$savecookiestr=serialize($savecookieid); //use serialize() to store the array
	setcookie("randompostsviewed",$savecookiestr,time()+3600*1,COOKIEPATH, COOKIE_DOMAIN); //keep for 1 hour by default 

}

if (isset($_COOKIE['randompostsviewed'])){
			$savecookiestr = $_COOKIE['randompostsviewed'];
			$savecookieid = unserialize($savecookiestr);
			}
			else{
				$savecookieid = array();
			} 
			$savecookieid[] = get_option("sticky_posts");
?>

<?php 

$args = array(
		'post_status' => 'publish',
		'caller_get_posts'=> 1,
		'post__not_in' => $savecookieid, 
		'orderby' => 'rand', 
		'posts_per_page' => 5
		);

		query_posts($args); 
	  
?>

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

<?php if (!in_array($post->ID,$savecookieid,true)) {
			 $savecookieid[]= $post->ID;
			 }
			fris_run_cookie($savecookieid);
?>
			
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<h2 class="entry-title"><a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a></h2>

<div class="entry-content">
<?php the_content(); ?>
</div>

<?php endwhile; ?>
<?php endif; ?>
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote