I’m making a timeline using this awesome free theme.
As you can see in this theme, it’s a timeline separated by “Page”.
We have “Page 1” with 5 articles, “Page 2” with 5 articles, etc …
I changed this by :
- “Page 1” become -> September
- “Page 2” become -> October
- “Page 3” become -> November
to adapt this theme in real timeline. It works great.
My ultimate problem is that I don’t know how to set number of articles per page number. It’s like 4 articles per all pages, that’s it. ( Ofcourse, I know how to set this value ).
Like this : I wrote 3 articles in September, and 4 in October.
With this usecase, my 3 articles wrotes in September will be in “September page” , and the first of article wrote in October will be also in “September page”.
So my question is simple, can i set the number of articles per number page ?
- Page 1 ( Septembre ) : 4 articles max.
- Page 2 ( October ) : 8 articles max.
- Page 3 ( November ) : 1 articles max.
After some searchs, i saw this code sample :
add_action( 'pre_get_posts', 'set_posts_per_page' );
function set_posts_per_page( $query ) {
global $wp_the_query;
if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) {
$query->set( 'posts_per_page', 3 );
}
elseif ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_archive() ) ) {
$query->set( 'posts_per_page', 5 );
}
// Etc..
return $query;
}
source : Change Posts per page count
This is exactly what i want, but no on “article category” but on page number
as (my pseudo code)
if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_page(1) ) {
$query->set( 'posts_per_page', 4 ); // **SEPTEMBER**
}
if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_page(2) ) {
$query->set( 'posts_per_page', 3 ); // **OCTOBER**
}