I'm building a custom theme with wordpress and have make a custom post type archive for my news items. I want to use the paginate (); function to navigate trough my items. This function doesnt work yet, what am i doing wrong?
<div class="col-md-12">
<?php
$args = array('post_type' => 'nieuws-item');
$the_query = new wp_query( $args );
while($the_query -> have_posts()) : $the_query -> the_post();?>
<div class="col-md-6 left">
<div class="content-holder-nieuws fc3 left">
<h6><?php the_title(); ?></h6>
<h6 class="month fc2 left"><?php echo (types_render_field("nieuws-maand", array("output"=>"normal"))); ?></h6>
<div class="news-discription left">
<p class="fc5 left">
<?php the_excerpt(); ?>
</p>
<a href="<?php the_permalink(); ?>" class="left read-more">
<img src="<?php bloginfo('template_url'); ?>/img/readmore-border.png" class="readmore-border">
lees meer
</a>
</div>
</div>
</div>
<?php endwhile; ?></div>
<div class="col-md-12 overview-navigation left">
<?php paginate_links(); ?>
</div>
Custom post types have archive functionality built in, you simply have to enable it. In your
register_post_type()
call, set 'has_archive' to true.Then create a template file for the archive page (if it's formatted differently to your standard blog). In your case I'm guessing you'll want to call it
archive-nieuws-items.php
. On your archive page you can then simply use the standard post loop rather than the custom version in your example.By taking this approach you're increasing efficiency as well as dealing with the pagination issue.
Further reading: https://codex.wordpress.org/Function_Reference/register_post_type https://developer.wordpress.org/themes/basics/template-hierarchy/