Hey all i'm running a query loop in a custom page.php
using a custom post type. I would for it to paginated so i could have a specific amount of post per page. I was wondering if someone could help me out. I have added my code below:
<?php query_posts( array(
'post_type' => array( 'POSTTYPE' ),
'showposts' => -1 )
); ?>
<?php while ( have_posts() ) : the_post(); ?>
<div class="">
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<?php the_post_thumbnail( 'thumbnail' , array('class' => 'aligncenter project_post_thumbnail') ); ?>
<a href="<?php the_permalink();?>">View </a>
</div>
<?php endwhile; ?>
Thanks!
The problem as wordpress.org documentation says:
Pagination won't work correctly, unless you set the 'paged' query var appropriately: adding the paged parameter
Example of usage:
<?php
$args = array(
'cat' => '5',
'post_type' => 'POSTTYPE',
'posts_per_page' => 6,
'paged' => ( get_query_var('paged') ? get_query_var('paged') : 1),
);
query_posts($args);
while (have_posts()) : the_post();
/* Do whatever you want to do for every page... */
?>
<a href="<?php the_permalink();?>"><?php the_title(); ?></a>
<?php the_post_thumbnail( 'thumbnail' , array('class' => 'aligncenter project_post_thumbnail') ); ?>
<a href="<?php the_permalink();?>">View </a>
<?php
endwhile;
?>
<div class="navigation">
<div class="alignleft"><?php previous_posts_link('« Previous') ?></div>
<div class="alignright"><?php next_posts_link('More »') ?></div>
</div>
<?php
wp_reset_query(); // Restore global post data
?>
Also you can check rvoodoo guide if you have more questions about it.