PDA

View Full Version : Random Post 0.1



Nick
05-25-2010, 11:34 PM
Random Post
Version: 0.1
Author: Nick Ramsay
Created: 2010/05/26
Last Updated: 2010/06/04
Tested on: Hotaru 1.2.0 ~ 1.3.0
Plugins Required: None
Plug & Play: No
Supported: Yes

Description
Displays a random *top* story.

Instructions
1. Upload the "random_post" folder to your plugins folder.
2. Install it from Plugin Management in Admin.
3. Add a link to a template for users to click:


<a href="<?php echo $h->url(array('page'=>'random')); ?>">Random Top Story</a>Revision History
v.0.1 2010/05/26 - Nick - Released first version

Please click "Rate Thread" and give this plugin a rating. Thank you.

kmai
08-29-2010, 12:31 PM
Nick,

Please, how it works Random Post?

Thanks

Nick
08-29-2010, 12:58 PM
When you click "Random Top Story", the browser redirects to a random "popular" post page. It's a very simple plugin. The entire code is this:


class RandomPost
{
/**
* If page is "Random"
*/
public function theme_index_top($h)
{
if ($h->pageName != 'random') { return false; }

$sql = "SELECT post_id FROM " . TABLE_POSTS . " WHERE post_type = %s AND post_status = %s ORDER BY RAND() LIMIT 1";
$post_id = $h->db->get_var($h->db->prepare($sql, 'news', 'top'));

if ($post_id) {
header("Location:" . $h->url(array('page'=>$post_id)));
exit;
}
}
}

kmai
08-29-2010, 01:36 PM
Thanks for the explanation