I have a custom post type called "Releases" set up and paginated perfectly using the following code:
The Loop
<?php
$paged = (get_query_var('page')) ? get_query_var('page') : 1;
$args = array( 'post_type' => 'releases', 'posts_per_page' => 3, 'paged' => $paged, 'page' => $paged );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
?>
<!-- Loop Content -->
<article>
<h3><?php the_title(); ?></h3>
<div><?php the_excerpt(); ?></div>
</article>
<!-- end Loop Content -->
<?php endwhile; ?>
<!-- Pagination -->
<?php
if (function_exists('single_view_pagination')) {
single_view_pagination($loop->max_num_pages,"", $paged);
}
?>
<!-- end Pagination -->
The Function
function single_view_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 2;
}
global $paged;
if (empty($paged)) {
$paged = 1;
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
$pagination_args = array(
'base' => get_pagenum_link(1) . '%_%',
'format' => 'page/%#%',
'total' => $numpages,
'current' => $paged,
'show_all' => False,
'end_size' => 1,
'mid_size' => $pagerange,
'prev_next' => True,
'prev_text' => __('«'),
'next_text' => __('»'),
'type' => plain,
'add_args' => false,
'add_fragment' => ''
);
$paginate_links = paginate_links($pagination_args);
if ($paginate_links) {
echo "<nav>";
echo "<ul>";
echo "<li>" . $paginate_links . "</li> ";
echo "</ul>";
echo "</nav>";
}
}
The Problem
Now, when using the code above and viewing the Archive of the custom post type, everything works perfectly and the pagination URLs link as followed:
http://localhost/releases/page/2
http://localhost/releases/page/3
However, when viewing the Single Post of the custom post type, the issue is that the pagination URLs change to:
http://localhost/releases/post-name/page/2
http://localhost/releases/post-name/page/3
Is there any way I can update this code or set up an new function in order to get the pagination URLs on the Single Post view to link properly & without the post-name in the URLs like this?
http://localhost/releases/page/1
http://localhost/releases/page/2
http://localhost/releases/page/3
All help is greatly appreciated. Thanks in advance!
Edit:
Here's a screenshot diagram showing exactly the issue that I am trying to fix. I need the function to output the page number links for the post type "Releases", instead of outputting the page number links of the current post "Post Name."
next_post_link
/previous_post_link
?base
argument sets the URL. Look at the output ofget_pagenum_link
and you'll see why you're getting those URLs from the function.