• Resolved fitzpatrick

    (@fitzpatrick)


    Hi, on single/permalink posts this:

    <div class="navposts"><?php previous_post_link('&laquo; %link') ?> &mdash; <?php next_post_link('%link &raquo;') ?>

    displays:

    ? prevposttitle — nextposttitle ?

    when viewing an “intervening” post so that there are both a previous post and a next post.
    But it displays:

    ? secondposttitle —

    when viewing the first post,

    — secondtolastposttitle ?

    when viewing the last post.

    How do I prevent the long dash (—) to display in these cases? I’m not practical with php. I suppose there’s if/else involved but i wouldn’t know how to write it.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m sure you could construct a php if/then snippet that would test for the presence of a previous or next post, but that seems like a bit of a pita to me.

    Being lazy, I’d either eliminate the &mdash; in the code snippet you posted, or just replace it with a character that doesn’t look as out of place to you, maybe &bull;

    https://www.evolt.org/article/A_Simple_Character_Entity_Chart/17/21234/

    Thread Starter fitzpatrick

    (@fitzpatrick)

    Hi, thanks for answering.

    The suggestion of replacing the dash with a subtler character is welcome. I had in mind something close: choosing | maybe one could apply a solution that I happened to find for a different case.
    This also shows that you are not that lazy…

    I think I’m going to follow the suggestion but at this very moment I’m actually in stubborn mode, as I downloaded this theme that I really like and found this minor bug that I will have to fix or die, I suppose…

    You’re welcome. Good luck in your quest. ??

    Thread Starter fitzpatrick

    (@fitzpatrick)

    I’m pretty sure this is not the proper or quickest way to do it, but it works.

    <?php if (!get_adjacent_post('', '', true)) : ?>
        <div class="navposts"><?php previous_post_link('&laquo;  %link') ?><?php next_post_link('%link &raquo;') ?></div>
        <?php elseif (!get_adjacent_post('', '', false)) : ?>
        <div class="navposts"><?php previous_post_link('&laquo;  %link') ?><?php next_post_link('%link &raquo;') ?></div>
        <?php else : ?>
        <div class="navposts"><?php previous_post_link('&laquo; %link') ?> &mdash; <?php next_post_link('%link &raquo;') ?></div>
      <?php endif ; ?>

    Here some notes.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘previous/next_post_link used like posts_nav_link on single/permalink post’ is closed to new replies.