posts_nav_link(); not showing up on static pages

I’ve got two different loops. The default on the homepage, but a secondary loop on the archive page. It grabs all the content, like so:

<?php // WP_Query arguments
$args = array (
    'posts_per_page'         => '3'
);
// The Query
$archiveQuery = new WP_Query( $args );

// The Loop
if ( $archiveQuery->have_posts() ) {
    while ( $archiveQuery->have_posts() ) {
        $archiveQuery->the_post(); ?>
        <div class="post">
<a href="https://wordpress.stackexchange.com/questions/131177/<?php the_permalink() ?>">
    <?php  first_item(); ?> </a>

However, when I include posts_nav_link();, it does not show up. Is this because it is a static page? I am using this for an infinite scroll.

2 Answers
2

posts_nav_link is intended for archive pages. That function uses get_next_posts_nav_link which uses the global variable $wp_query. There is a check for !is_singular(). That will always be false on your “static” page, since $wp_query will represent the page (single) and not the query you have created. So, yes, it is because it is a static page.

Chip Bennett wrote/compiled an fairly exhaustive answer explaining how to make pagination work.

Leave a Comment