我有一个自定义的帖子类型,名为“Releases“使用以下代码完美地设置和分页:
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
现在,当使用上面的代码并查看
Archive 对于自定义post类型,所有内容都能正常工作,分页URL链接如下:
http://localhost/releases/page/2
http://localhost/releases/page/3
但是,在查看
Single Post 对于自定义帖子类型,问题是分页URL更改为:
http://localhost/releases/post-name/page/2
http://localhost/releases/post-name/page/3
是否有任何方法可以更新此代码或设置新函数以获取
pagination URLs on the Single Post view 正确链接(&A);没有像这样的URL中的帖子名称?
http://localhost/releases/page/1
http://localhost/releases/page/2
http://localhost/releases/page/3
非常感谢您的帮助。提前感谢!
Edit:这是一张截屏图,显示了我正试图解决的问题。我需要函数output the page number links for the post type “发布”,instead of outputting the page number links of the current post “职位名称。”