A
A
Alexander Sharomet2015-12-04 22:26:03
Programming
Alexander Sharomet, 2015-12-04 22:26:03

How to set up pagination in Wordpress?

Hello.
I'm not a programmer and I naturally had a problem in Wordpress.
I display all the posts on one of the pages they have a thumbnail and those that don't.
while doing this I need to add pagination. numbers are added and even pages are switched but the posts remain the same

<?php
      $args = array('posts_per_page');
      $lastposts = query_posts($args);
      foreach($lastposts as $post):?>
      <div class="post-sidebar">
        <?php if(has_post_thumbnail()):?>
          <div class="media media2">
            <div class="media-left">
              <a href="<?php the_permalink();?>"><?php the_post_thumbnail();?></a>
            </div>
            <div class="media-body">
              <p class="pos-date m-b-0"><?php echo get_the_date('F j, Y, gA',$post);?></p>
              <?php setup_postdata($post);?>
              <h4 class="m-t-0"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h4>
              <p><?php echo wp_trim_words(get_the_content(),66).' '; ?><br />
              <a href="<?php the_permalink();?>" class="more-style">+ Read More.</a></p>
            </div>
          </div>
        <?php else:?>
          <p class="pos-date m-b-0"><?php echo get_the_date('F j, Y, gA',$post);?></p>
          <?php setup_postdata($post);?>
          <h4 class="m-t-0"><a href="<?php the_permalink();?>"><?php the_title(); ?></a></h4>
          <p><?php echo wp_trim_words(get_the_content(),70).' '; ?><br />
          <a href="<?php the_permalink();?>" class="more-style">+ Read More.</a></p>
        <?php endif;?>
      </div>
      <?php 
        endforeach;
        wp_reset_postdata();
      ?>
      
      
      <?php 
        the_posts_pagination(array(
          'type'=>'list',
          'mid_size'=> 1,
          'screen_reader_text'=> __('')
        ));
      ?>

Where am I wrong.
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2015-12-05
@sharomet

Paste this:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$lastposts = query_posts('posts_per_page=5&paged=' . $paged);

...instead of this:
$args = array('posts_per_page');
$lastposts = query_posts($args);

Documentation: https://codex.wordpress.org/Pagination#Adding_the_...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question