I'm having some trouble with some code for my WordPress category pagination. I have built a theme with custom categories, where all posts from a given category are displayed throughout various pages on the site.
The actual pagination is working fine, the 'Older Entries' and 'Newer Entries' links do indeed work properly. My problem is the way they are implemented into the code does not allow me to wrap them in tags in order to style them.
I also am unable to move them to outside of the "row" class. This causes a problem when an uneven number of posts show up on the last page, the 'Older' and 'Newer' links then show up immediately after the last post and not in a new row underneath as I would like. I've been trying to create a workaround for hours now and am stuck. Any help would be appreciated!
<?php get_sidebar(); $cat_id = get_query_var('cat'); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main ajax_posts" role="main">
<div class="container-fluid trizzy-posts-container">
<div class="row">
<div class="home-categorytitle">
<h2>Discover</h2>
</div>
<?php
//PRINT ONLY DISCOVER
$current_page = get_queried_object();
$category = $current_page->post_name;
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$query = new WP_Query(
array(
'paged' => $paged,
'category_name' => $category,
'order' => 'des',
'post_type' => 'post',
'post_status' => 'publish',
)
);
if ($query->have_posts()) {
while ( $query->have_posts() ) {
$query->the_post(); ?>
<div class="col-xs-12 col-sm-6 col-md-4">
<?php get_template_part('template-parts/content','discover'); ?>
</div>
<?php
}
// next_posts_link() usage with max_num_pages
next_posts_link( 'Older Entries', $query->max_num_pages );
previous_posts_link( 'Newer Entries' );
wp_reset_postdata();
}
?>
</div><!-- .row closing -->
</div><!-- .container-fluid closing -->
</main><!-- #main closing -->
</div><!-- #primary closing -->
<?php get_footer(); ?>