Archive page: chronological numbering w/ reverse-chronological display ordering?
-
Using Astra I have archive pages containing titles and excerpts from 10 blog entries each, and when a new blog entry is written its title and excerpt go to the front. So the front archive page always has titles and excerpts from the 10 most recent blog entries, and the archive pages are arranged in reverse chronological order. This is pretty standard.
The problem is that the archive pages are not only ARRANGED in reverse chronological order: they are also NUMBERED in the same order. Thus the front page is labelled page 1, and the 10 entries posted BEFORE its 10 entries are on page 2. Correspondingly, “next page” refers to the next higher number. So for example the “next page” after page 7 contains excerpts from the 10 articles posted BEFORE the articles that are excerpted on that page.
I need the numbering to be the other way round.
For example if there are 117 entries than I want the page referring to the most recent entries (the 108th to the 117th) to be called page 12, and the previous page to that one (referring to the 98 the to 107th) to be called page 11.
This isn’t such a peculiar thing to do. It’s how issues of periodicals are numbered, for example.
How can I achieve this, whether by amending functions.php in the child theme (preferably), by writing a “Snippet” (next most preferred), or by amending archive.php in the Astra parent theme directly (least preferred, because of possible update problems)?
I know how to renumber the posts into direct chronological order, namely using the following PHP code. But unfortunately this DISPLAYS them in numerical order, which has now been reversed. So it causes the earliest posts to be excerpted on the front archive page rather than the latest ones!
<?php
add_filter(‘pre_get_posts’, ‘posts_by_forward_date’);
function posts_by_forward_date($query) {
if(is_archive() || is_home()) {
$query->set(‘order’, ‘ASC’);
}
}
?>Any help will be much appreciated!
- The topic ‘Archive page: chronological numbering w/ reverse-chronological display ordering?’ is closed to new replies.