Answer the question
In order to leave comments, you need to log in
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'=> __('')
));
?>
Answer the question
In order to leave comments, you need to log in
Paste this:
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$lastposts = query_posts('posts_per_page=5&paged=' . $paged);
$args = array('posts_per_page');
$lastposts = query_posts($args);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question