• Hello,
    I’m trying to use next_posts_link and previous_posts_link in a loop generated by WP_Query (query_posts would do the same) but I’m having problems with “previous_posts_link”.

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $latest_news_query = new WP_Query(array('post_type' => 'post', 'posts_per_page' => 2, 'paged' => $paged));
    
    if($latest_news_query->have_posts()):
      while ($latest_news_query->have_posts()) :
        $latest_news_query->the_post();
        [...]
      endwhile;
    
      previous_posts_link('Older');
      next_posts_link('Newer');
    
    endif;

    – If I go to “/my-page/” (the main page) the ‘Older’ link doesn’t show.
    – If I go to “/my-page/page/2/” (the second paginated page) the ‘Newer’ link pointing to /my-page/ it’s shown while the ‘Older’ not.
    The 2 could be changed with 3,4,5… and the result is the same

    Anyone could help me?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter ShMk

    (@shmk)

    Anyone could tell me if I’m using the previous_posts_link() and next_posts_link() correctly?
    Are they to use in different situations?
    Am I doing any error?

    your code looks right.

    have you checked if the link is in the html code in the browser?

    it might be off screen or otherwise obscured.

    does the ‘older’ link show when you are on the last of your paged pages, i.e. if the ‘newer’ link should not show?

    a link to your site might get you more responses.

    Thread Starter ShMk

    (@shmk)

    Hi alchymyth and thanks for your reply.

    > have you checked if the link is in the html code in the browser?

    No, the link is not hidden somewhere in the code.

    > does the ‘older’ link show when you are on the last of your paged pages, i.e. if the ‘newer’ link should not show?

    The older link show also in “middle” pages, not just the last one (and the “newer” doesn’t appear in middle pages).

    > a link to your site might get you more responses.

    Sorry but I cannot link it because it’s on a development server.

    Thread Starter ShMk

    (@shmk)

    Other 2 informations that could be useful:
    – the page that contains the posts is not a default “Page” but a custom template.
    – maybe previous_posts_link() doesn’t work if I’m using WP_Query to retrieve the posts?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Navigation using next/previous_posts_link’ is closed to new replies.