In a custom page template, I use the following code to display posts from that category and sub-category.
How do I make the pagination work?
// The Query
query_posts( array ( 'category_name' => 'publicatii', 'posts_per_page' => 4 ) );
// The Loop
while ( have_posts() ) : the_post();
echo '<h1>';
the_title();
echo '</h1>';
the_excerpt();
echo ' <p class="postinfo">Written by: ';
the_author_posts_link();
echo 'Posted on ';
the_date();
echo 'Categories: ' ;
the_category( ', ' );
echo '</p>' ;
endwhile;
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?paged=%#%',
'current' => max( 1, get_query_var( 'paged' ) ),
'total' => $wp_query->max_num_pages
) );
// Reset Query
wp_reset_query();
get_footer();
As an example, it does change the link (page/2/
... page/3/
), but it does not change the posts from that page (still the same posts).
query_posts
should never be used, under any circumstances, and is the primary reason behind your lack of pagination. There are better ways of querying for posts or changing the posts WordPress displays