我在我的 Wordpress 主题中为自定义帖子类型添加了分页。它工作得很好,除了它在分页菜单中显示的帖子数量过多:http ://www.electrickiwi.co.uk/testimonials/
当前应该有 7 页,但显示的是 12 页。下面的代码是我用来显示分页的代码。functions.php 文件中没有与此相关的内容。
<?php
/* ------------------------------------------------------------------*/
/* PAGINATION */
/* ------------------------------------------------------------------*/
//paste this where the pagination must appear
global $wp_query;
$total = $wp_query->max_num_pages;
// only bother with the rest if we have more than 1 page!
if ($total > 1) {
// get the current page
if (!$current_page = get_query_var('paged')) {
$current_page = 1;
}
// structure of "format" depends on whether we're using pretty permalinks
if (get_option('permalink_structure')) {
$format = 'page/%#%/';
}
else {
$format = 'page/%#%/';
}
echo paginate_links(array(
'base' => get_pagenum_link(1) . '%_%',
'format' => $format,
'current' => $current_page,
'total' => $total,
'mid_size' => 4,
'type' => 'list'
));
}
?>