I have two custom post types, Categories
and Videos
. Each and every category has multiple videos. I have a single page for categories
and the category single page shows the videos
added under those categories.
Now I want the pagination to be added to the videos that are being shown in the single category page.
Following is the single-categories.php
<?php
get_header();
//Page Title Bar
echo page_title_bar();
?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php
$category_id = get_the_ID();
$comingsoon = get_field('coming_soon');
$description = get_field('category_description');
?>
<!-- Page Container -->
<div class="container page-container">
<?php $args = array(
'numberposts' => -1,
'post_type' => 'Videos',
'order' => 'ASC',
'post_status'=>'publish'
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()):
while ($the_query->have_posts()) : $the_query->the_post(); ?>
<!-- HTML of Videos -->
<?php endwhile; ?>
<!-- Pagination -->
<div class="pagination-wrapper">
<?php pagination(); ?>
</div>
<!-- End of Pagination -->
<?php endif; ?>
</div>
<!-- End Page Container -->
<?php endwhile; endif;?>
<?php get_footer(); ?>
pagination()
function is added to the function.php
function pagination($pages = '', $range = 4, $paged = null) {
if ($paged == null) {
global $paged;
}
if (empty($paged)) {
$paged = 1;
}
if ($pages == '') {
global $wp_query;
$pages = $wp_query->max_num_pages;
if (!$pages) {
$pages = 1;
}
}
if (1 != $pages) {
echo "<ul class='pagination'><li><a>Page " . $paged . " of " . $pages . "</a></li>";
echo '<li><a href="' . get_previous_posts_page_link() . '">«</a></li>';
for ($i = 1; $i <= $pages; $i++) {
if (1 != $pages && (!($i >= $paged + $range + 1 || $i <= $paged - $range - 1) || $pages <= $showitems )) {
echo ($paged == $i) ? "<li class=\"active\"><a>" . $i . "</a></li>" : "<li><a href='" . get_pagenum_link($i) . "' class=\"inactive\">" . $i . "</a></li>";
}
}
echo '<li><a href="' . get_next_posts_page_link($pages) . '">»</a></li></ul>';
}
}
What the above code does is it filter the number of videos(If I set the reading to 10 it only shows first 10 videos), but doesn't show the next, previous page buttons. At the same time, the pagination is working fine on the blog page.