function pagination_bar($posts_per_page) {
$published_posts = wp_count_posts()->publish;
$total_pages = ceil($published_posts / $posts_per_page);
if ($total_pages > 1){
$current_page = max(1, get_query_var(\'paged\'));
echo paginate_links(array(
\'base\' => get_pagenum_link(1) . \'%_%\',
\'format\' => \'?paged=%#%\',
\'current\' => $current_page,
\'total\' => $total_pages,
));
} }
将上述代码置于功能中。php。
<?php pagination_bar($post_details[\'posts_per_page\']); ?>
上面的函数调用是需要显示分页的地方。
然后使用wp\\u查询获取所有帖子,如examble
<?php
if ( get_query_var(\'paged\') ) $paged = get_query_var(\'paged\');
if ( get_query_var(\'page\') ) $paged = get_query_var(\'page\');
$post_details = array(\'post_type\'=> \'post\',\'paged\'=>$paged,\'numberposts\' => -1,\'posts_per_page\' => 2);
$custom_query = new WP_Query( $post_details );
?>