Archive pagination not working
I am trying to add pagination for my Archive. I want to show 12 posts per page and then show the 'next' / 'previous' buttons.
When I manually change the value of the $paged variable, the 1 into a 2 it works. When I click the Next button on the archive page, it loads a very weird theme page. The url looks like: '/page/2/'.
What am I doing wrong?
This is the code I wrote so far:
?php
global $paged,$wp_query;
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'post_type' = 'realisaties',
'posts_per_page' = 12,
'paged' = $paged,
'order' = 'ASC'
);
$archive_query = new WP_Query($args);
while ($archive_query-have_posts()) : $archive_query-the_post();
$image = get_field('preview_afbeelding');
if( !empty($image) ):
$url = $image['url'];
$title = $image['title'];
$alt = $image['alt'];
$caption = $image['caption'];
// thumbnail
$size = 'medium';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];
if( $caption ): ?
div class="wp-caption"
?php endif; ?
div class="col-md-3"
?php echo get_the_title(); ?
a href="?php the_permalink() ?" title="?php echo $title; ?"
img class="realisatie-img img-responsive" src="?php echo $thumb; ?" alt="?php echo $alt; ?" title="" width="?php echo $width; ?" height="?php echo $height; ?" /
br /
/a
/div
?php if( $caption ): ?
h2 ?php echo get_the_title(); ?/h2
p class="wp-caption-text"?php echo $caption; ?/p
/div
?php
endif;
endif;
endwhile;
?
?php next_posts_link('Older Entries »', $archive_query-max_num_pages); ?
?php previous_posts_link('Newer Entries', $archive_query-max_num_pages); ?
?php wp_reset_query(); ?
/div
/div
Topic pagination archives Wordpress
Category Web