View Single Post
Old 06-21-2013, 06:39 AM  
tonyparra
Confirmed User
 
tonyparra's Avatar
 
Industry Role:
Join Date: Jul 2008
Location: In your back seat with duck tape
Posts: 4,568
Weird Wordpress Random Query Issue

Im using a random query on a wordpress tube theme to insert a random number of post in index page before the regular post. For some reason, the query works fine on the home page, but if you surf to the second page, it doesnt work.

Code:
<?php 
	$temp = $wp_query;
	$wp_query= null;
	$wp_query = new WP_Query();
	$wp_query->query('showposts=20&orderby=rand');
	while (have_posts()) : the_post();
?>              
post content
<?php endwhile; wp_reset_query()?>
this is a custom pagination function being used (*i didnt write this snippet came with the theme)
Code:
//Pagination function
function pagination($pages = '', $range = 6)
{
     $showitems = ($range * 2)+1; 
 
     global $paged;
     if(empty($paged)) $paged = 1;
 
     if($pages == '')
     {
         global $wp_query;
         $pages = $wp_query->max_num_pages;
         if(!$pages)
         {
             $pages = 1;
         }
     }  
 
     if(1 != $pages)
     {
         echo "<span>Page ".$paged." of ".$pages."</span>&nbsp;&nbsp;";
         if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a class=\"pFirst\" href='".get_pagenum_link(1)."'>First</a>";
        // if($paged > 1 && $showitems < $pages) echo "<a href='".get_pagenum_link($paged - 1)."'>&lsaquo; Previous</a>";
         for ($i=1; $i <= $pages; $i++)
         {
             if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
             {
                 echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".get_pagenum_link($i)."' class=\"inactive\">".$i."</a>";
             }
         }
        // if ($paged < $pages && $showitems < $pages) echo "<a href=\"".get_pagenum_link($paged + 1)."\">Next &rsaquo;</a>";
         if ($paged < $pages-1 &&  $paged+$range-1 < $pages && $showitems < $pages) echo "<a class=\"pLast\" href='".get_pagenum_link($pages)."'>Last</a>";
         
     }
}
I dont see any reason for them to conflict, they work fine on the home page , looking for answers from someone better at wp than me
__________________

High Performance Vps $10 Linode
Manage your Digital Ocean, Linode, or Favorite Cloud Server. Simple, fast, and secure Server Pilot
tonyparra is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote