A
A
Alexey102020-05-25 11:00:06
WordPress
Alexey10, 2020-05-25 11:00:06

Change the value of have_posts when adaptive?

Guys, how to change the value of the have_posts cycle? That is, so that 12 posts are displayed on the computer, and 5 on the phone, for example?

$params = array(
  'posts_per_page' => 12,
);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WP Panda, 2020-05-25
@wppanda5

What is the correct way to specify pre_get_posts output?

A
Alexander, 2020-05-25
@a-kh

You can use https://wp-kama.ru/function/wp_is_mobile.

$params = array(
     if( wp_is_mobile() ){ // Если с мобильных устройств
          'posts_per_page' => 5, // показываем 5 постов
     } else { // если с других устройств
          'posts_per_page' => 12, // показываем 12 постов
     }
);

This is a definition of mobile devices, not just the width of the browser. But, most likely, in 95% of cases it will cover normally.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question