나는 이것을 사용자 지정 페이지 매김에 사용하고 있으며 잘 작동합니다.
//paginations for newsletter
//define in function file
function custom_pagination($numpages = '', $pagerange = '', $paged='') {
if (empty($pagerange)) {
$pagerange = 2;
}
/**
* This first part of our function is a fallback
* for custom pagination inside a regular loop that
* uses the global $paged and global $wp_query variables.
*
* It's good because we can now override default pagination
* in our theme, and use this function in default queries
* and custom queries.
*/
if ($paged == '') {
global $paged;
if (empty($paged)) {
$paged = 1;
}
}
if ($numpages == '') {
global $wp_query;
$numpages = $wp_query->max_num_pages;
if(!$numpages) {
$numpages = 1;
}
}
/**
* We construct the pagination arguments to enter into our paginate_links
* function.
*/
$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' => true,
'add_fragment' => '',
'after_page_number' => '',
'before_page_number' =>'',
);
$paginate_links = paginate_links($pagination_args);
if ( $paginate_links ) {
echo "<nav class='custom-pagination'>";
//echo "<span class='page-numbers page-num'>Page " . $paged . " of " . $numpages . "</span> ";
echo $paginate_links;
echo "</nav>";
}
}
?>
// template-newsletter와 같은 템플릿에 대해 이것을 정의하십시오.
<?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$newslatter_detail = array(
'post_type' => 'newsletter',
'post_status' => 'publish',
'posts_per_page' =>4,
'order' => 'ASC',
//'orderby' =>'date',
'paged' => $paged
);
$posts = new WP_Query( $newslatter_detail );
$posts_array = get_posts( $newslatter_detail );
if ( $posts -> have_posts() ) {
while ( $posts->have_posts() ) : $posts->the_post();
the_title();
endwhile;
wp_reset_postdata();
} else { ?>
No Forum List found.
<?php } ?>
<div class="pagination">
<?php
if (function_exists(custom_pagination)) {
custom_pagination($posts->max_num_pages,"",$paged);
}
?>
</div>