If you’re encountering issues with custom post pagination, here are some suggestions to enhance your implementation.
Custom Post Query:
Ensure your custom post query is correctly set up for the ‘download‘ post type. Here’s an example:
<?php
global $wp_query;
query_posts(array('post_type' => array('download'), 'paged' => $paged));
?>
Loop through Posts and Display Content:
Make sure you are looping through your custom posts and displaying the content using ‘content-item.php‘. The loop structure should look similar to this:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part('content', 'item'); ?>
<?php endwhile; ?>
Pagination Output:
Include the pagination output within the loop if posts are available. Utilize the ‘st_posts_pagination‘ function to generate pagination links:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php get_template_part('content', 'item'); ?>
<?php endwhile; ?>
<div class="col-md-12">
<div class="page-link text-center">
<?php st_posts_pagination(); ?>
</div>
</div>
<?php endif; ?>
Pagination Function Code:
Ensure that the ‘st_posts_pagination‘ function is correctly defined and operational. Here is an improved version of your provided code:
if (!function_exists('st_posts_pagination')) {
function st_posts_pagination()
{
global $wp_query;
if ($wp_query->max_num_pages > 1) {
$big = 999999999; // An unlikely integer
$pagination_args = array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'prev_next' => true,
'current' => max(1, get_query_var('paged')),
'total' => $wp_query->max_num_pages,
'type' => 'array',
'prev_text' => __('« Previous', 'your-theme-textdomain'),
'next_text' => __('Next »', 'your-theme-textdomain'),
);
$items = paginate_links($pagination_args);
$pagination = '<ul class="pagination">' . "\n\t<li>";
$pagination .= join("</li>\n\t<li>", $items);
$pagination .= "</li>\n</ul>\n";
echo $pagination;
}
return;
}
}
By following these steps and ensuring that your custom post query, loop, and pagination function are correctly configured, you should be able to resolve any issues with custom post pagination.
Leave a Reply