1

I have archive pages that each contain titles and excerpts from 10 blog entries. Both entries and archive pages are in reverse chronological order:

  • when a new blog entry is written its title and excerpt go to the top of the front page;

  • when you are on one page and you click through to "Next page", you get the titles and excerpts for the 10 previous blog entries.

This is pretty standard for blogs.

But the archive pages are numbered by default in the same order. Thus Page 1 contains excerpts from the most recent 10 entries, Page 2 contains excerpts from the next 10 most recent, etc.

To be clear: at the moment, "Next page" refers to the page with the next higher number. Thus the front page, which contains excerpts from the most recent entry and the nine next most recent entries, is labelled Page 1, and the 10 entries posted before those 10 entries are on Page 2.

I need the page-numbering the other way round, namely in direct chronological order, so that for example if there are 97 entries then

  • entries 28-37 would be excerpted on Page 4, and
  • the PREVIOUS page from there, containing excerpts from entries 18-27, would be called page 3.

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)?

Edit

The following isn't a solution but it may be part of one. This re-numbers pages into direct chronological order, but unfortunately it also reverses the order in which they are shown (from reverse chronological to direct chronological). So it causes the front archive paget to contain excerpts from the earliest posts 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');
  }
}
?>
8
  • You should be able to do this "amending archive.php in the Astra parent theme" but instead create a copy of the file and then add it to your child theme where you're free to make edits as needed. You may need to periodically check the Astra updates/changelogs to see if they modified that file so you can address anything you yourself may need to update. (This is the third time today someone's asked about this theme... ...is this the new Avada?) Apr 18, 2020 at 0:42
  • Thanks, @TonyDjukic, but what should I actually write in functions.php or whatever the appropriate file in the parent theme is? I've got as far as being able to number the posts forward in time (as described in the edit), but something is still showing them in numerically indexed order on the archive page, which kinda defeats the purpose. I want them in backwards chronological order (i.e. newest first) and also backwards numerical order (just as the current issue of a periodical will have a higher number than a previous issue).
    – user169591
    Apr 18, 2020 at 0:47
  • Unless someone on here is really familiar with the Astra theme and it's templates it's going to be really difficult for anyone to actually answer. You can try posting the archive.php code here and see if someone can help address that. Apr 18, 2020 at 0:49
  • I can do that if you like, but that file has a lot of dependencies.
    – user169591
    Apr 18, 2020 at 3:57
  • 1
    I've reopened the question, and made some edits, in particular the title. It read as a textbook theme help question, that you actually wanted to change how pagination numbers work was difficult to prise out. It still needs modifications as it's not easy to understand but i've done what i can to make the question clearer, and there's still some ambiguity. E.g. do you mean you want the numbers to appear 10, 9 ,8 ,7 ,6... 1? Or do you mean if you have 20 pages, that visiting the archive jumps straight to page 20?
    – Tom J Nowell
    Apr 19, 2020 at 11:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.