只需使用此功能:
function wpse279455_query_pagination( $the_query, $pagination_args = array() ) {
global $wp_query;
// Make backup of the query object
$original_query = $wp_query;
// Swap the global query with our custom qyert
$wp_query = $the_query;
// Call the pagination function while custom query is set
the_posts_pagination( $pagination_args );
// Restore the query from backup
$wp_query = $original_query;
}
当您有一个新的WP\\U查询对象时,只需按如下方式传递它:
// My awesome query
$my_query = new WP_Query( array(
\'post_type\' => \'my_cpt\',
\'posts_per_page\' => 10,
) );
// Show the pagination for this query
wpse279455_query_pagination( $my_query, array(
\'mid_size\' => 2,
\'prev_text\' => __( \'Back\', \'textdomain\' ),
\'next_text\' => __( \'Onward\', \'textdomain\' ),
) );