WordPress.org

Forums

How Do I Add "Older Posts" and "Newer Posts" Links to my Blog? (13 posts)

  1. agfreesafety
    Member
    Posted 3 years ago #

    I just realized that the theme I'm using for my blog doesn't have the "Older Posts" and "Newer Posts" links at the bottom of the page that allow people to get to the older posts that I created.

    I was told that I needed to add the below code to my index.php file, which I did, but the links still aren't showing up.

    <?php next_posts_link('Older Posts'); ?>
    <?php previous_posts_link('Newer Posts'); ?>

    Did I need to do more than just simply paste the above code in the bottom of my index.php file?

  2. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Did I need to do more than just simply paste the above code in the bottom of my index.php file?

    Yes; you need to paste that code in the correct place within your template file.

    The links need to go outside the Loop, specifically, outside of the while( have_posts() ) part of the Loop.

  3. agfreesafety
    Member
    Posted 3 years ago #

    [Code moderated as per the Forum Rules. Please use the pastebin]

  4. agfreesafety
    Member
    Posted 3 years ago #

    Sorry for posting all of that, I was just trying to show that I placed the code at the end, which I believe meets your specification of it being outside of that loop.

    The loop you're speaking of is way at the beginning of the index.php (which I pasted above). Please let me know if you see something I did wrong. And thanks for your time.

  5. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    It looks like you pasted the code outside of the document body. Try putting it where the wp_pagenavi() function call is.

  6. agfreesafety
    Member
    Posted 3 years ago #

    I'm sorry, I don't know anything about PHP, would you be so kind as to tell me where exactly the code should be placed? Please bear with me.
    Below is what I have near the wp_pagenavi() function call.

    Should I paste them both before the </div> tag right before the "Page Number" commented line?

    <script src="http://pastebin.com/embed_js.php?i=UcWwTb0Y"></script>

  7. agfreesafety
    Member
    Posted 3 years ago #

    I was trying to paste the section of my code above using Pastebin, but I don't know how to use pastebin yet, obviously.

  8. Chip Bennett
    Theme Review Admin
    Posted 3 years ago #

    Replace this:

    <div class="pagenavi">
    <?php if( function_exists( 'wp_pagenavi ' )) { wp_pagenavi(); } ?>
    </div>

    With this:

    <div class="pagenavi">
    <?php if( function_exists( 'wp_pagenavi ' ) ) {
         wp_pagenavi();
    } else {
         next_posts_link('Older Posts');
         previous_posts_link('Newer Posts');
    } ?>
    </div>
  9. you pretty much succceeded with the pastebin.

    click the pastebin link http://pastebin.com/;
    paste your code into the large field;
    select 'syntax highlighting' , for instance 'PHP';
    click 'submit';
    copy the new address in the top browser address bar;
    post this url here.

    Should I paste them both before the </div> tag right before the "Page Number" commented line?

    yes

  10. agfreesafety
    Member
    Posted 3 years ago #

    Got it working now, fellas. Thanks so much!

  11. ORMGrecipes
    Member
    Posted 3 years ago #

    I'm having the same problem. I tried pasting the code above in my index.php file, but it's not working. I pasted my index.php file in pastebin and here's my URL: http://pastebin.com/u9CFr5xx

    Does anyone know where I put these codes at?
    <?php next_posts_link('Older Posts'); ?>
    <?php previous_posts_link('Newer Posts'); ?>

  12. ORMGrecipes
    Member
    Posted 3 years ago #

    Nevermind, everyone. I had my settings off. Fixed the problem.

  13. NicoMorrison
    Member
    Posted 3 years ago #

    I am using 3.2.1 + K2 theme & I'm not sure in which file I should add this code?

    Can anyone tell me where to put the 'older/newer' posts (at the bottom) code? Do I make a /local file so the original can be updated OK?

    Thank you in advance,
    Nico Morrison
    London UK

Topic Closed

This topic has been closed to new replies.

About this Topic