EDIT: This is the current code that I'm trying to paginate. It creates a custom query that excludes the latest post, as well as all posts from one category. Pagination works fine for the most part, but the problem is that the final link in the pagination list takes me to a blank page.
<section class="card-grid card-grid--push">
<main class="container container--wide">
<?php
$current_page = get_query_var('paged');
$current_page = max( 1, $current_page );
$per_page = 3;
$offset = ( $current_page - 1 ) * $per_page + 1;
$post_list = new WP_Query(array(
'cat' => -15,
'posts_per_page' => $per_page,
'paged' => $current_page,
'offset' => $offset,
'orderby' => 'date',
'order' => 'DESC',
));
if ( $post_list->have_posts() ):
while ( $post_list->have_posts() ):
$post_list->the_post();
?>
<a href="<?php the_permalink(); ?>" <?php post_class('card'); ?>>
<article class="card__content">
<?php the_post_thumbnail('th-card'); ?>
<div class="card__head">
<span class="category">
<?php $category = get_the_category(); echo $category[0]->cat_name; ?>
</span>
<h2 class="card__title"><?php the_title(); ?></h2>
</div>
</article>
</a>
<?php endwhile; ?>
<div class="pagination">
<?php
echo paginate_links( array(
'total' => $post_list->max_num_pages,
'current' => $current_page,
'type' => 'list',
'prev_text' => '?',
'next_text' => '?'
) );
?>
</div>
<?php
endif;
wp_reset_postdata();
?>
</main>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…