说明: 到达最后一页后,一期。 分页有效。
问题: 第一篇文章(第1页中的第一篇文章)也将显示在末尾(在本例中为第2页)。
我的自定义帖子类型:
$labels = array(
'name' => _x( 'Parks', 'post type general name', 'your-plugin-textdomain' ),
'singular_name' => _x( 'Park', 'post type singular name', 'your-plugin-textdomain' ),
);
$args = array(
'labels' => $labels,
'description' => ":D",
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'parks' ),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 5,
'menu_icon' => 'dashicons-palmtree',
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments')
);
register_post_type( 'parkpt', $args );
}
add_action( 'init', 'create_parkpt' );
我的查询:
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = [
'post_type' => 'parkpt',
'posts_per_page' => '5',
'orderby' => 'date',
'paged' => $paged,
];
$parks = New WP_Query($args);
if ($parks->have_posts()): while($parks->have_posts()): $parks->the_post();
我的分页:
<?php
$GLOBALS['wp_query'] = $parks;
the_posts_pagination( [
'prev_text' => '<a href="#" class="page-link" aria-label="Previous"><i class="ti-angle-left"></i></a>',
'next_text' => '<a href="#" class="page-link" aria-label="Next"><i class="ti-angle-right"></i></a>',
'before_page_number' => '<span href="#" class="page-link">',
'after_page_number' => '</span>',
'screen_reader_text' => ' ',
'total' => $parks->max_num_pages,
] );
wp_reset_postdata( );
分页在默认帖子类型上可以完美工作。 建议非常感谢!