I want to display one more WordPress top page on the list of articles.

Asked 1 years ago, Updated 1 years ago, 88 views

I would like to display one more WordPress front page on the list of articles.

Default number of articles displayed: 6

For example, the front page (page 1) → 7
Top page (page 1) → 6
Category Tag Archive (page 1) → 6
Category Tag Archive (page 2) → 6

It's like

By the way, I have used this as a reference.

·Change the number of WordPress listings on page 1 and after page 2|Storaip

There is one more article on all the first pages.I want the category tag archive to be the default number.

Thank you for your advice.

php html css wordpress

2022-09-30 21:26

2 Answers

Why don't you branch this process with is_home()?
https://wpdocs.osdn.jp/ Function Reference/is_home


2022-09-30 21:26

The policy of this program is to set the total number of blogs to 6, exceptionally the top page to 7, followed by the offset calculation to 6.
Set Administration Screen Settings = > Display Settings = > Maximum Posts to Display on Page 1 to 6.

Open functions.php and write:

define('PAGE_1ST', 7);
define('PAGE_2ND', get_option('posts_per_page'));
function change_posts_paging($query){
  $paged=get_query_var('paged') ?intval(get_query_var('paged')—1;
  if(is_home()&&$paged==1&!is_admin(){
    $query->set('posts_per_page',PAGE_1ST);
  } elseif(is_home()&$paged>=2&&!is_admin(){
    $query->set('offset', PAGE_1ST + PAGE_2ND*($paged-2));
    $query->set('posts_per_page',PAGE_2ND);
  }
}
add_action('pre_get_posts','change_posts_paging');

If it doesn't work, try is_home() to is_front_page().


2022-09-30 21:26

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.