【发布时间】:2021-05-17 00:11:32
【问题描述】:
我正在按发布日期 DESC 显示我的自定义帖子 3 每页顺序。有 8 个帖子,我想要的只是在第 1 页,它应该显示帖子 8 和 7,而不是 8、7、6。 所以分页应该是:
第 1 页:8,7
第 2 页:6,5,4
第 3 页:3,2,1
function get_paginated_links( $query ) {
$currentPage = max( 1, get_query_var( 'paged', 1 ) );
$pages = range( max( 1, $query->max_num_pages ), 1 );
return array_map( function( $page ) use ( $currentPage ) {
return ( object ) array(
"isCurrent" => $page == $currentPage,
"page" => $page,
"url" => get_pagenum_link( $page )
);
}, $pages );
}
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
$posts_per_page = 3;
$the_query = new WP_Query(
array(
'posts_per_page' => $posts_per_page,
'paged' => $paged,
'orderby'=> 'publish_date',
'order' => 'DESC'
)
);
foreach( get_paginated_links( $the_query ) as $index => $link ) :
echo the_content();
endwhile;
上面的代码在第一页显示了post 8,7,6。我该如何解决?
【问题讨论】:
标签: php wordpress pagination wordpress-hook