Next post URL

Hi,

If I use the function: next_post_link()

I can have wordpress to automatic add the next link link in my theme. I however just want the url for the next link, so I can do some more tweaking to the since I want to add some classes and so on.

How do I get that ?

  • kprimdal
    • Flash Drive

    Sorry, was maybe a bit to fast.

    I manage to find this:

    <?php $nextpost = get_adjacent_post(true,'',false); ?>
    <?php $prevpost = get_adjacent_post(true,'',true); ?>
    <div class="nav-previous"><a href="<?php echo get_permalink($prevpost); ?>">Tilbage</a></div>
    <div class="nav-next"><a href="<?php echo get_permalink($nextpost); ?>">Frem</a></div>

    Now the problem is just when I come to the end the links are still there and does not dissapear

  • Philip John
    • DEV MAN’s Apprentice

    Hiya!

    Looks like you just need to wrap that lot in a couple of IF statements, like so;

    <?php if ($nextpost = get_adjacent_post(true,'',false)) : ?>
    <div class="nav-previous"><a href="<?php echo get_permalink($prevpost); ?>">Tilbage</a></div>
    <?php endif; ?>
    <?php if ($prevpost = get_adjacent_post(true,'',true)): ?>
    <div class="nav-next"><a href="<?php echo get_permalink($nextpost); ?>">Frem</a></div>
    <?php endif; ?>

    Note I haven't tested that so it *could* be wrong...

    Phil

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.