Good afternoon, help! On Wordpress, you need to make Next / Prev buttons inside category entries. What would these buttons always displayed. for example, inside a category of 5 pages, when the first one is displayed so that the prev button is displayed and when pressed, it moves to page 5, and next to the second. By standard means, the Prev button will display only from the second page. And on the first and second buttons there are no these!

  • What is the point to link to yourself? This loop is infinite. Not afraid of problems with seo and users' misunderstandings? - mihdan

1 answer 1

Good day! I quickly added a small piece of code here. Of course, it’s better to wrap it up as a function and place it in functions.php for later use anywhere:

//Формируем аргументы для запроса массива постраничной навигации $args = array( 'base' => str_replace( $big, '%#%', get_pagenum_link( $big ) ), 'current' => max( 1, get_query_var('paged') ), 'total' => $wp_query->max_num_pages, 'type' => 'array', 'prev_next' => false, ); //Получаем постраничную навигацию в виде массива $result = paginate_links( $args ); //Получаем количество элементов в массиве $pagCount = count($result); //Текущая страница в постраничной навигации $current_page = max( 1, get_query_var('paged') ); //Вся постраничная навигация $simple_pagination = ""; $counter = 0; foreach ($result as $simPage) { $counter = $counter + 1; $simple_pagination .= '<br><a href="/page/'.$counter.'">'.$counter.'</a>'; } //Выводим ссылки на предыдущую и следующую страницу if($current_page == 1) { $pagination .= '<br><a href="/page/'.($pagCount).'">Предыдущая страница</a>'; } else { $pagination .= '<br><a href="/page/'.($current_page-1).'">Предыдущая страница</a>'; } //Добавляем "внутренние" страницы в постраничную навигацию $pagination .= $simple_pagination; if($current_page == $pagCount) { $pagination .= '<br><a href="/page/1">Следующая страница</a>'; } else { $pagination .= '<br><a href="/page/'.($current_page+1).'">Следующая страница</a>'; } echo $pagination; 

Everything is based on the Wordpress paginate_links () function