WordPress pagination showing same results for each page

Pagination for my website seems to be showing the same results for each page. I believe this has something to do with me using multiple loops. I can’t seem to get it show different posts for any of the other pages that have been paginated, example: /page/2/ or /page/3/ and so forth.

Loop one:

Read More
<?php 
global $do_not_duplicate;
$do_not_duplicate = array();

    $my_query = new WP_Query('category_name=top-story&posts_per_page=1');
    while ($my_query->have_posts()) : $my_query->the_post();
        $do_not_duplicate[] = $post->ID;?>
        <div class="yl_bg_post main_content videos">
            <div class="top_story"><p>Top Story</p></div>
            <h2 class="title"><?php the_title(); ?></h2>
            <?php the_content('<p class="more">More></p>'); ?>
        </div>
<?php endwhile; ?>

Loop two:

<?php 
$my_query = new WP_Query('category_name=small-story&posts_per_page=1');
    while ($my_query->have_posts()) : $my_query->the_post();
        $do_not_duplicate[] = $post->ID;?>
        <div class="more_break">
        <?php
        $perma = get_permalink();
        echo "<a href='".$perma ."'>";
        the_content("") . "</a>";
        echo '<a href="' . $perma . '"><p class="more">More></p></a>';
        $count++;
        ?>
    </div>
    <?php endwhile; ?>

Final loop:

while (have_posts()==the_post()) {
if (in_array($post->ID, $do_not_duplicate)) {} ?>
        <div class="yl_bg_post main_content videos">
        <h2 class="title"><?php the_title(); ?></h2>
    <?php the_content('<p class="more">More></p>'); ?>
</div>
<?php } ?>

Pagination:

<?php
    global $wp_query;
    $total_pages = $wp_query->max_num_pages;    

    if ($total_pages > 1){
        $current_page = max(1, get_query_var('paged'));
        echo paginate_links(array(
            'base' => get_pagenum_link(1) . '%_%',
            'format' => 'page%#%',
            'current' => $current_page,
            'total' => $total_pages,
            'prev_text' => '',
            'next_text' => 'Next'
            ));
    }
?>

What my website does is just display the same content for each page… I can’t seem to find a solution to this issue. Apologises if I’ve missed anything, if I have i will add it as soon as possible.

Related posts

Leave a Reply

2 comments

  1. You need to pass the paged parameter into your query as well.

    $paged = max(1, get_query_var('paged'));
    $my_query = new WP_Query('category_name=top-story&posts_per_page=1&paged='.$paged);