最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

themes - How to reverse the pagination numbers of an archive?

programmeradmin2浏览0评论

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');
  }
}
?>
发布评论

评论列表(0)

  1. 暂无评论