P
P
PakoGonsalezZ2018-06-26 14:44:06
WordPress
PakoGonsalezZ, 2018-06-26 14:44:06

What did I do wrong in pagination of custom posts?

I display user posts on the page, pagination is necessary, I took an example from here
ls-web.ru/paginatsiya-spiska-kastomnyh-postov The
pagination itself, I output the code, as in other sections
Here is the code

<?php
                        global $wp_query;
$page = (get_query_var('paged')) ? get_query_var('paged') : 1;                    
$per_page = 5;
$offset = ($page-1)*$per_page;
            $posts = query_posts( [
              'post_type'  => 'private_posts',
                            'posts_per_page'  => $per_page,
                            'offset'          => $offset,
              'author__in' => [$q_user_id]
              ] );
                            $current_page = $page;
                            
             while ( have_posts() ) : the_post(); 
            ?>
            <li>
                        
              <div class="block-img" style="background-image: url(<?= get_the_post_thumbnail_url( $post->ID, 'full' ); ?>);">
                <!-- <img src="<?= get_template_directory_uri(); ?>/img/img-1q.png"> -->
                <span><?= get_the_date('d.m.y', $post->ID); ?></span>
              </div>
              <div class="edit-article">
                <h2><?= $post->post_title; ?></h2>
                <?php if ($q_user_id == wp_get_current_user()->ID) { ?>
                <a href="<?= get_permalink( $edit_article_id ); ?>?id=<?= $post->ID; ?>"><img src="https://toppols.ru/wp-content/themes/toppol/img/redakt.png"> редактировать статью</a>
                <?php } ?>
              </div>
              
              <span class="lines"></span>	
              <p><?= $post->post_excerpt; ?></p>
              <div class="block-bottom">
                <p class="block-left"><a href="<?= get_the_permalink( $post->ID ); ?>" class="chit">Читать</a></p>
                <p class="block-right">
                  <span><img src="<?= get_template_directory_uri(); ?>/img/oco.png"><?= GetCounts__SPVC($post->ID); ?></span>
                  <!--<span><img src="<?= get_template_directory_uri(); ?>/img/like.png">5</span>-->
                  <span><img src="<?= get_template_directory_uri(); ?>/img/coment.png"><?php plural_form(get_comments_number($post->ID), array('комментарий','комментария','комментариев')); ?></span>
                </p>
              </div>
            </li>
            <?php
            endwhile; ?> 
                        
          </ul>
  <div class="page-num">
                      	<? $pagination = paginate_links([
            'current' =>  $current_page,
            'type'    => 'array',
            'next_text' => ">",
            'prev_text' => "<"
          ]); ?>
            <? category_pagination($pagination); 
                        wp_reset_query();
                        ?>

Paination is considered and displayed, but the second page is empty
https://toppols.ru/blogi/vse-o-samostoyatelnom-mon...
Tell me what's wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PakoGonsalezZ, 2018-06-26
@PakoGonsalezZ

I achieved the output of the second pagination page, in function.php I found an address handler that loaded another template on the pagination page, fixed it, but now the same content is displayed on the second pagination page - the first 5 elements

S
sinistra17, 2018-06-26
@sinistra17

There was a similar problem, I solved it by using just have_posts() instead of query_posts() (having looked at how it is implemented in a standard template with working plugins), but then it is impossible to select the number of posts on the page, the standard number will be displayed
Try to look in this article , it is analyzed in detail why this error occurs and how to solve it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question