WordPress - 如何在模板上启用分页


Wordpress - How can I enable pagination on template?

如何使用

以下查询在自定义模板上显示分页?

$args = array (
'post_type'              => 'post',
    'posts_per_page'         => '24',
    'pagination'             => true,
    'tax_query' => array(  
    array(  
        'taxonomy' => 'category',  
        'field' => 'term_id',  
        'terms' => $mh_terms
    )  
)  

(;

另外,我在 while 循环结束时使用它:

next_posts_link(); 
previous_posts_link(); 

试试这个

<?php
    $paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
    $args = array (
        'post_type' => 'post',
        'posts_per_page' => '24',
        'pagination' => true,
        'paged' => $paged,
        'tax_query' => array(  
        array(  
            'taxonomy' => 'category',  
            'field' => 'term_id',  
            'terms' => $mh_terms
        ) , 
    ),);  
    $wp_query = new WP_Query($args);
    while ($wp_query->have_posts()): $wp_query->the_post();
    get_the_title();
    endwhile;
    global $wp_query;
    $big = 999999999; // need an unlikely integer
    echo paginate_links( array(
        'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format' => '?paged=%#%',
        'current' => max( 1, get_query_var('paged') ),
        'total' => $wp_query->max_num_pages
    ) );
?>