WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Previous/next posts links showing when I don't need them to (7 posts)

  1. Abledaccess
    Member
    Posted 3 years ago #

    I can't seem to track down what I'm after, which convinces me I'm going about it the wrong way.

    I'm developing a theme with accessibility foremost in mind. It's very simple so far, and I'm currently adding to it. But first I need to take something away. Namely the code WordPress outputs, in this particular circumstance. I'm specifically attempting to address pagination -- I'm not entirely sure that is the proper term. But the previous/next post links that appear on the index, archive and search pages?

    I'm attempting to have said links sit in an unordered list. Trick is how do I have the list not appear when there isn't other pages? Plus not have the previous posts link list item output on the last page and same deal with the next posts link list item on the first page? Is this even possible?

    I've managed to dig up some code that makes this behaviour happen sans the list, but that isn't what I'm trying to accomplish. I've found a solution for my single template and, for consistencies sake a least, I'd really like it be the same. Well it would be working if I had more than one post published. But same goes for that instance. How would I make the unordered list not show when it's not needed.

    My site is http://abledaccess.com. Any help would greatly be appreciated. Thanks.

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    try and work with get_next_posts_link() and get_previous_posts_link() resp.

    http://codex.wordpress.org/Function_Reference/next_posts_link

    rough example:

    $nexts = get_next_posts_link();
    $prevs = get_previous_posts_link();
    if( $nexts || $prevs ) { ?>
    <ul>
    <?php if( $nexts ) echo '<li>'.$nexts.'</li>';
    if( $prevs ) echo '<li>'.$prevs.'</li>'; ?>
    </ul>
    <?php } ?>
  3. Abledaccess
    Member
    Posted 3 years ago #

    Thanks a lot alchymyth,

    Beautiful! Does exactly what I need it to. Brilliant!

    Sorry for the delay. I'm trying to learn PHP, at the same time as hacking around with WordPress. Which means I tried, and was successful, well half successful, to customize the above bit of code for my purposes. Not to mention also in an attempt to understand it. Which I'm pretty sure I do.

    But, and I'm not wanting to push my good fortune, how might I customize what the output link says? I tried to define new variables, and they output what I wanted, but the link to the corresponding pages disappeared from the text. What did I not do right?

    Anyway thanks a million...

  4. alchymyth
    Forum Moderator
    Posted 3 years ago #

    how might I customize what the output link says?

    do you mean the wording of the links?

    you might have read the linked docu: http://codex.wordpress.org/Function_Reference/next_posts_link
    and:
    http://codex.wordpress.org/Function_Reference/previous_posts_link

    you can set this in the function directly:
    http://codex.wordpress.org/Function_Reference/next_posts_link#Working_example

    I tried to define new variables, and they output what I wanted, but the link to the corresponding pages disappeared from the text. What did I not do right?

    no idea without seeing the code ...

  5. Abledaccess
    Member
    Posted 3 years ago #

    Sorry. "The wording of the links" is exactly what I meant. Of course! I see. In retrospect, kind of a silly question. Thank you. I see what I was doing incorrectly. No worries, at all. Wonderful!

    You've given much to work with. So, in theory, would get_adjacent_post, on my single template, used in the this instance, meaning hoping for the same result, yield the same thing? Never mind. Sorry for the jumbled over thought. I'll try it out, and see what happens.

    Thanks a ton.

  6. alchymyth
    Forum Moderator
    Posted 3 years ago #

    would get_adjacent_post, on my single template, used in the this instance, meaning hoping for the same result, yield the same thing?

    yes,
    possibly just using get_adjacent_post() for the conditional statements, and using next_post_link() and previous_post_link() for the link text.

    http://codex.wordpress.org/Function_Reference/next_post_link
    http://codex.wordpress.org/Function_Reference/previous_post_link
    http://codex.wordpress.org/Function_Reference/get_adjacent_post

  7. Abledaccess
    Member
    Posted 3 years ago #

    Amazing. I got it working. Thanks a million.

Topic Closed

This topic has been closed to new replies.

About this Topic