• Hi there.

    I am trying to use the <?php previous_post_link (); ?> call inside an <a href> tag to provide the link for a previous post on a single page. I’m trying to do this with no text, to make img navigation buttons.

    Does that make sense? =)

    Gratzi.

Viewing 3 replies - 1 through 3 (of 3 total)
  • That tag doesn’t work on Pages.
    If you meant a single post > take a look at this plugin: http://guff.szub.net/2005/01/18/next-previous-post-img/

    Thread Starter recyclemysoul

    (@recyclemysoul)

    Is there any way not to use a plugin? Can you just wrap the php tag into an href so it pulls the link for the previous and next post while an img src is the only thing displayed?

    And yes, I meant a single post (single.php from the common Kubrick theme)

    You can output just the url to next and previous posts with a few internal WordPress functions, and a bit of PHP. First, collecting the basic info (ID and post title) for the next and previous posts:

    <?php
    $next_post = get_next_post();
    $prev_post = get_previous_post();
    ?>

    This resides in your template within The Loop, but before the links. Then for your image links, here’s an example for next post:

    <a href="<?php echo get_permalink($next_post->ID); "><img srv="/images/next.png" title="<?php echo str_replace('"', '\'', $next_post->post_title); ?>" /></a>

    The above makes use of the PHP function str_replace() to convert " to ' (and avoid any validation issues in the title attribute).

    Previous post is no different:

    <a href="<?php echo get_permalink($prev_post->ID); "><img srv="/images/previous.png" title="<?php echo str_replace('"', '\'', $prev_post->post_title); ?>" /></a>

    Note the next and previous post url stuff is duplicated in a plugin of mine:

    http://wordpress.org/support/topic/51091#post-280466

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How do I correctly use <?php previous_post_link (); ?> in a href…?’ is closed to new replies.