• Resolved jabbamonkey

    (@jabbamonkey)


    I am having trouble with adding a next_posts_link. It isn’t appear on my page. Below is some code that I have at the bottom of my homepage, which shows a listing of my most recent posts. The posts are showing up fine … but I need a way to show a link to “older posts” …

    Can someone tell me what I am doing wrong, or how I can do this?

    <?php
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $numposts = 5;
    $postsarg = array (
    		'cat' => '-2222,-2223,-2224,-299,-2231',
    		'posts_per_page' => $numposts,      //for testing purposes
    		'paged' => $paged
      );
    $the_query = new WP_Query( $postsarg );
    while ($the_query -> have_posts()) : $the_query -> the_post();
    	get_template_part( 'excerpts' );
    endwhile;
    ?>
    <!-- End BLOG ROLL -->
    
    <?php next_posts_link('Older Posts'); ?>
Viewing 6 replies - 1 through 6 (of 6 total)
  • vtxyzzy

    (@vtxyzzy)

    Thread Starter jabbamonkey

    (@jabbamonkey)

    That didn’t work. It added the OLDER POSTS LINK, and when you click it, it takes you to http://www.website.com/page/2/ …. BUT, it just returns me to the homepage with the same initial 5 posts.

    <?php
    $numposts = get_field('blogroll');
    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $postsarg = array (
    		'cat' => '-2222,-2223,-2224,-299,-2231',
    		'posts_per_page' => $numposts,      //for testing purposes
    		'paged' => $paged
      );
    $the_query = new WP_Query( $postsarg );
    while ($the_query -> have_posts()) : $the_query -> the_post();
    	get_template_part( 'excerpts' );
    endwhile;
    ?>
    <!-- End BLOG ROLL -->
    
    <?php next_posts_link( 'Older Entries', $the_query->max_num_pages ); ?>
    vtxyzzy

    (@vtxyzzy)

    Please try changing get_query_var(‘paged’) to get_query_var(‘page’).

    Thread Starter jabbamonkey

    (@jabbamonkey)

    Ok, that worked for the pagination… and the posts are showing up, and the OLDER POSTS is pointing to the homepage with the next 5 posts…

    But I still have a problem…
    In my theme, I have content on homepage that should ONLY appear on the homepage. When I click the OLDER POSTS link, it KEEPS that content on top of the homepage.

    Is there an IF-ELSE condition that I can use to only show this homepage content?

    Note, this doesn’t seem to work: if(is_front_page() || is_home()) { } else { }

    vtxyzzy

    (@vtxyzzy)

    Are you saying that the content should only appear on page 1 of the home page? If so, this should work:

    if ((is_front_page() || is_home()) && $paged == 1) {} else {}
    Thread Starter jabbamonkey

    (@jabbamonkey)

    Awesome. That worked great. Thanks for the help!

    Situation fixed and resolved!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘next_posts_link not showing up on page’ is closed to new replies.