Previous/next posts links showing when I don't need them to
-
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.
-
try and work with
get_next_posts_link()
andget_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 } ?>
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…
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_linkyou can set this in the function directly:
http://codex.wordpress.org/Function_Reference/next_posts_link#Working_exampleI 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 …
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.
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 usingget_adjacent_post()
for the conditional statements, and usingnext_post_link()
andprevious_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_postAmazing. I got it working. Thanks a million.
- The topic ‘Previous/next posts links showing when I don't need them to’ is closed to new replies.