WordPress.org

Support

Support » Themes and Templates » Maintain Random Post with Pagination

Maintain Random Post with Pagination

  • Hi all,

    I have a page template for my theme that display’s all posts randomly.
    This is a paged template, and the posts are randomising on each page. So you’ll get some posts showing on more than one page and some posts that don’t show at all.

    I’ve found a couple of solutions that involve using a function to add a seed arguement to RAND, but none that seem to work. in fact most give me php errors.

    my current template code is below:

    Just wondering if anyone can point me in the right direction?

    Thanks:

    <?php while (have_posts()) : the_post(); 
    
    				$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    				$args = array( 'posts_per_page' => -1,
    					   'offset'=> 0,
    					   'post_type' => 'portfolio');
    
    				$all_posts = new WP_Query($args);
    
    				while($all_posts->have_posts()) : $all_posts->the_post();
    
    			?>
    
    				<a id="post-<?php the_ID(); ?>" href="<?php the_permalink(); ?>" data-name="<?php echo $post->post_name; ?>"><?php echo $post->post_name; ?></a>
    
    			<?php endwhile; ?>
    		<?php endwhile; ?>
    
    		</div>
    
    		<section id="portfolio" class="folioGrid clearfix">
    			<?php while (have_posts()) : the_post(); 
    
    				$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
    				$args = array( 'posts_per_page' => 20,
    					   'offset'=> 0,
    					   'post_type' => 'portfolio',
    					   'orderby' => 'rand',
    					   'portfolio_category' => $portfolio_filter,
    					   	'paged' => $paged);
    
    				$all_posts = new WP_Query($args);
    
    				while($all_posts->have_posts()) : $all_posts->the_post();
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Maintain Random Post with Pagination’ is closed to new replies.