I
I
Ingvar Von Bjork2018-01-30 23:37:29
WordPress
Ingvar Von Bjork, 2018-01-30 23:37:29

How to make pagination in Wordporess?

I want to make pagination when selecting a category. ( cx80363-wordpress.tw1.ru/category/toys/)
Sample code working on category.php:

<?php query_posts(array(
'cat' => 1,
'paged' => 1,
'post_per_page' => '1'
));

if ( have_posts() ) while (have_posts()) : the_post(); ?>
<?php endwhile; ?>
<?php the_posts_pagination(); ?>

Displays the page navigation itself, but when you try to navigate, nothing happens.
What am I doing wrong?
WP 4.9.2
Self-written template

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ingvar Von Björk, 2018-01-31
@DeboshiR

As a result, I decided to get the page number using WP.
The code is like this:

<?php $pageNum=(get_query_var('paged')) ? get_query_var('paged') : 1; //получаем текущую страницу

        query_posts(array(
          'cat' => get_cat_ID($cat_title),
          'paged' => $pageNum, //передаем текущую страницу
          'post_per_page' => 1
        ));

        if ( have_posts() ) :
          while ( have_posts() ) : the_post(); ?>
            /* посты */
          <?php endwhile;
          the_posts_pagination();
        else :
        endif; ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question