I am displaying my custom posts 3 per page order by published date DESC. There are 8 posts and all I want is on page 1, it should display post 8 & 7, rather than 8,7,6.
So the pagination should be:
page 1: 8,7
page 2: 6,5,4
page 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;
The above code shows post 8,7,6 on the first page. How do I fix it?
2
Answers
I ended up doing like this. It definitely can be improved. I will take this for now.
You can use
post__in
param to show only 8,7 for page 1. check the below code.USEFUL LINKS