beluoso
beluoso

Reputation: 107

Wordpress custom loop pagination - always same content

I have one custom loop in a custom homepage in WordPress that is pulling 4 posts with some banners in middle. All is working fine, however pagination always shows same posts. Is there a way for me to add pagination to this custom loop?

My index.php code:

<?php
query_posts(array(
'post_type' => 'post',
'showposts' => 4,
) );
?>

<?php if (have_posts()) : ?>
<?php $count = 0; ?>
<?php while (have_posts()) : the_post(); ?>
<?php $count++; ?>
<?php if ($count == 3) : ?>

<!-- banners -->

<a href="<?php the_permalink(); ?>"> <h1> <?php the_title(); ?>  </h1>  </a>
<?php the_content(); ?>
<?php else : ?>
<a href="<?php the_permalink(); ?>"> <h1> <?php the_title(); ?>  </h1>  </a>
<?php the_content(); ?>

<!-- banners -->

<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

<p align="center"><?php posts_nav_link(); ?></p>

Upvotes: 0

Views: 345

Answers (1)

Joint
Joint

Reputation: 1218

Inside your query_post array add this line:

'paged' => ( get_query_var('paged') ) ? get_query_var('paged') : 1,

and in settings -> reading set 4 posts per blog page.

Upvotes: 1

Related Questions