With the help of the Option Tree plugin I made the setting for displaying certain rubrics on the main page.

<?php get_header(); $a = 5; ?> <div class="content content-pos"> <div class="row portfolio "> <?php $str_cat = ''; if (!empty(ot_get_option('my_category'))) { // echo '1'; /* get the slider array */ $slides = ot_get_option('my_category', array()); if (!empty($slides)) { foreach ($slides as $slide) { $str_cat = $str_cat . $slide['category_ch'] . ','; } } } $args = array( 'cat' => $str_cat ); $query = new WP_Query($args); if ($query->have_posts()): // для проверки clearfix $clear_md = 0; $clear_sm = 0; ?> <?php while ($query->have_posts()): $query->the_post(); //считаем clearfix $clear_md++; $clear_sm++; ?> <div class="col-md-4 col-sm-6 col-xs-12 nop"> <div class="content__block content__block-pos z-depth-1"> <div class="content__top"> <a href="<?php the_permalink(); ?>" class="content__img content__img-pos"><?php the_post_thumbnail(); ?> </a> <h3 class="content__title content__title-pos"><a href="<?php the_permalink(); ?>" class="" title="<?php the_title(); ?>"><?php the_title() ?></a> </h3> <div class="content__article content__article-pos"><?php the_excerpt() ?></div> </div> <div class="content__bottom"> <div class="divider"></div> <a href="<?php the_permalink(); ?>" class="content__read waves-effect content__read-pos"><span> Read more</span> </a> </div> </div> </div> <?php // вставляем clearfix if ($clear_md % 3 == 0) { echo ' <div class="clearfix visible-md-block visible-lg-block"></div>'; } if ($clear_md % 2 == 0) { echo ' <div class="clearfix visible-sm-block"></div>'; } ?> <?php $start_row++; endwhile; ?> <?php endif; wp_reset_postdata(); ?> </div> </div> <div class="content"> <?php pagination(); ?> </div> <?php get_footer(); ?> 

I created a separate file with category.php, so that index.php would not interfere with the display of posts in the rubrics page. Column pages work well. But pagination appears on the main page !!! The main page displays only 4 posts (out of 6 allowed), and for some reason pagination appears on the 2nd page, where the same 4 posts. Why did it happen?

  • js snippets for js, {} that's for code. - Naumov
  • Surely the pagination() function works for the main request ("main loop"). Your posts are displayed by a special (not the main) request, and this function does not know about them, but it knows about posts that are displayed by default on the main one. Find out exactly where this function is defined and add it to the text of the question, and then we'll see - tutankhamun
  • @tutankhamun thank you very much, your answer is correct, changed the pagination function, everything works. - Alexander Alekseev

3 answers 3

I will assume that the pagination appears because of this part of the code

 <div class="content"> <?php pagination(); ?> </div> 

Try to remove it.

  • Pagination should be, and work when necessary. Now there is no need. - Alexander Alekseev
  • then it would be logical to bring the code of the function that is responsible for the work of pagination, telepaths rarely come in here - alenkins
  • Well, yes, the work is already enough :) - tutankhamun

Good evening! You can try this:

Replace your code:

 <div class="content"> <?php pagination(); ?> </div> 

On this design:

 <div class="content"> <?php if(!is_home()) { pagination(); } ?> </div> 

is_home () - checks what page is displayed. Here is the doc .

  • Thank you, but it will not work for me, I don’t say that there will be only 4 entries, maybe 10-20, I made the settings for the user to make it easier for him to display the entries he wants on the main page. That is, pagination is needed, but only when it is required. - Alexander Alekseev
  • There is a suspicion that you are trying to redefine the number of posts on the main page; this is not recommended. According to Wordpress help, the right thing to do is through "Options" -> "Reading" -> "On the pages of the blog, display no more." Check how many posts you have there for the conclusion. - D. Lomov

The answer is as follows: If you change the request for the cycle of displaying posts on a page, then you need to change the request for the output of pagination for the same page!