Random posts on a page
-
how can i add random full(exactly as on the homepage ) posts on a page like http://www.example.com/random
-
http://ww.wp.xz.cn/extend/plugins/random-posts-plugin/
http://rmarsh.com/plugins/post-options/
read about placement on a page with the [shortcode]I assume you will use query_posts on your page to retrieve the posts. For the random loop, use a query similar to this:
$args = array( 'orderby' => 'rand', 'posts_per_page' => 5 ); query_posts($args); if (have_posts()) . . .This will show 5 random posts.
Edit: oops – samboll beat me to it.
i found a solution `<?php query_posts(array(
‘orderby’ => ‘rand’
));
if (have_posts()) : while (have_posts()) : the_post();?>`
is there a way to excude already seen posts?
and any idea on how to paginate it ?
i have something in place<?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?></div>but it only pagintes the mainpage not the page template i created for the random posts
the pagenavi function in integrated in the theme it looks like thisfunction wp_pagenavi($before = '', $after = '', $prelabel = '', $nxtlabel = '', $pages_to_show = 5, $always_show = true) { global $request, $posts_per_page, $wpdb, $paged; if(empty($prelabel)) { $prelabel = '<strong>«</strong>'; } if(empty($nxtlabel)) { $nxtlabel = '<strong>»</strong>'; } $half_pages_to_show = round($pages_to_show/2); if (!is_single()) { if(!is_category()) { preg_match('#FROM\s(.*)\sORDER BY#siU', $request, $matches); } else { preg_match('#FROM\s(.*)\sGROUP BY#siU', $request, $matches); } $fromwhere = $matches[1]; $numposts = $wpdb->get_var("SELECT COUNT(DISTINCT ID) FROM $fromwhere"); $max_page = ceil($numposts /$posts_per_page); if(empty($paged)) { $paged = 1; } if($max_page > 1 || $always_show) { echo "$before <div class='Nav'><span>Page $paged of $max_page</span>"; if ($paged >= ($pages_to_show-1)) { echo '<a href="'.get_pagenum_link().'">« First</a> ... '; } previous_posts_link($prelabel); for($i = $paged - $half_pages_to_show; $i <= $paged + $half_pages_to_show; $i++) { if ($i >= 1 && $i <= $max_page) { if($i == $paged) { echo "<strong class='on'>$i</strong>"; } else { echo ' <a href="'.get_pagenum_link($i).'">'.$i.'</a> '; } } } next_posts_link($nxtlabel, $max_page); if (($paged+$half_pages_to_show) < ($max_page)) { echo ' ... <a href="'.get_pagenum_link($max_page).'">Last »</a>'; } echo "<div class='NavEnd'></div></div> $after"; } } } ?>Hi,
Check with this plugin:
http://ww.wp.xz.cn/extend/plugins/random-featured-post-plugin/
Thanks,
Shane G.
The topic ‘Random posts on a page’ is closed to new replies.