I have a realy big problem with pagination. When i click next post - wordpress show me the same 9 post. What is bad with this? This is meybe on $row array? I need custome post view, and pagination.
<?php
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'posts_per_page' => 9,
'paged' => $paged
);
$query = new WP_Query ( array( $args ) );
$row = array(6, 3, 3, 4, 4, 4, 3, 3, 6);
$i = 0;
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'thumbnail' );
?>
<div class="col-md-<?php echo $row[$i] ?> col-xs-6">
<div class="blog-item scrollpoint sp-effect2">
<div class="cover" style="background-image: url('<?php echo $thumbnail[0] ?>')">
<div class="mask">
<div class="post">
<span class="kategoria"></span>
<div class="tresc">
<h1> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
<div class="wypis"><?php echo get_the_excerpt(); ?></div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
$i++;
endwhile; ?>
<!-- pagination -->
<?php previous_posts_link('« Newer posts') ?>
<?php next_posts_link('Older posts »') ?>
<?php wp_reset_postdata();?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
The previous_posts_link and next_posts_link are designed to show the next or former post from the currently displayed post. You're displaying a loop.
If, as this seems, you are just making a blog index page and requesting regular posts, then you just need to make links that append /{paged}/ to the end, like so:
<a href="/blogpage/<?php echo $paged + 1; ?>/">Next</a>
<?php if($paged > 1): ?>
<a href="/blogpage/<?php echo $paged - 1; ?>/">Previous</a>
<?php endif;?>
Where blogpage is the page this is supposed to appear (if the home, just do / )
If you're doing something more complicated, like a custom post type with a custom permalink structure, look into query_vars and the Rewrite API .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.