• Hi!
    I am trying to make an image clickable, to take the user to the next / previous post.

    I have this code (the title is in a table, just for decoration!):

    <td rowspan=”2″ class=”arrow_deco”>
    “>
    <img src=”wp-content/themes/t/images/left.gif”>
    </td>

    etc..

    But the
    <?php previous_post(”, ”, ‘yes’); ?> and
    <?php next_post(”, ”, ‘yes’); ?>
    gives the post I AM ON!
    Not the previous / next..

    I have spent some time researching, but I can’t find the solution.
    Any idea what I am doing wrong?
    Johanna

Viewing 9 replies - 1 through 9 (of 9 total)
  • Actually, if you look at the source of your pages in a web browser, you’ll see they are not linking to anything at all (i.e. href=""). This is because you provide no format string for the link to catch on. So change your code to:

    <?php previous_post('%', '', 'yes'); ?>
    <?php next_post('%', '', 'yes'); ?>

    I’d also suggest looking at using previous_post_link() and next_post_link(), as the two above are considered deprecated in the WordPress code.

    http://codex.wordpress.org/Template_Tags/previous_post_link
    http://codex.wordpress.org/Template_Tags/next_post_link

    Thread Starter jojo0507

    (@jojo0507)

    Hi!
    Thanks for explaining. I am new this type of programming…
    I am definitely getting the right URL now. THanks.

    But please can you help a bit more?
    I can’t achieve something quite straightforward and it is driving me nuts.

    I’ll try to explain.
    Default way for the Next / Previous post layout seems to be something like this:

    Previous post:
    <<My Day at Work (with this being the hyperlink.)

    I have set up the header like table, to get everything to appear just where I want it. That’s working fine.

    The layout of the left side is like this:

    ————————————————
    | | Previous Post:
    | <img> |—————————————
    | | Excting Day (a clickable url) ————————————————

    All is working fine, except, I cannot get the <img> to be simply a clickable arrow!

    I have a pretty arrow picture called ‘left.gif’.

    I CAN get the arrow to display, either from the php file, or by making it a background image in the table cell.

    But I cannot find a way to hide the url text, and make the image clickable, to take the user to the previous page by clicking on that image.

    Is this possible, and how would you achieve it?
    Jo

    Thread Starter jojo0507

    (@jojo0507)

    please ignore the illustration in the previous post, it got corrupted while posting. Will teach me to preview before posting. Hope the post is comprehensible despite that.

    Don’t sweat the example. Your explanation covers it.

    Check out this thread where I provide a solution for using images for next and previous post links:

    http://wordpress.org/support/topic/91602#post-463228

    Let me know (in that thread) if I’m not clear on how to set things up.

    Thread Starter jojo0507

    (@jojo0507)

    Hi !
    I am trying out your advice, but no luck so far – it’s going slowly.

    The problem for me is probably that I am so new to .php. and even HTML…

    As soon as I have tried this to the best of my ability I’ll post back to say how it went!
    JO

    Thread Starter jojo0507

    (@jojo0507)

    Hi!
    I spent a few hours on and off with this now, and I cannot get it to work.

    I have been trying out the syntax that you are suggesting, but it is not compiling for me. I That is probably due to my lack of skills in PHP.

    It’s really frustrating though – programmatically it doesn’t seem like a difficult thing to do AT ALL, but I can’t find any documentation, and my skill level is too low to transform the code in your example to code that works for me 🙁

    I don’t have time to start thoroughly studying php, and I am not the fastest learner anyway.

    The arrows I want to make clickable are here at the top of the page:
    http://www.vikingprincess.net/?p=8
    The pages are not finished yet, so there is only dummy text in there. (I think that the arrows should be clickable because it is an intuitive thing for users to click on an arrow.)

    For the time being I’ll get on with other things on this theme, but I’ll check back on this post later.

    Thanks for trying to help!
    Jo

    Thread Starter jojo0507

    (@jojo0507)

    Hi Kafka,
    I pasted this inside “the loop” as recommended in the article.

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

    Then I used the syntax from the same example in this way, (just to get it to work before I do anything else):

    <div class=”testclass”>
    <A HREF=”<?php get_permalink($next_post->ID)?>”><img src= “http://www.vikingprincess.net/wp-content/themes/tiga/images/left.gif”/></A&gt;
    </div>

    The picture displays, but the link is for the post I am on. Not the previous post.

    I tried replacing the function inside the href tag with all sorts of php calls, but I am just not having any luck at all.

    RESULTS of what I have tried so far:
    —————————————
    <?php get_previous_post()
    -Gives URL for the page I’m ON.wrong

    <?php previous_post(‘%’, ”, ‘yes’); ?>
    -DISPLAYS the link instead of embedding it inside the image. The image is then not clickable. I tried a number of variations on this function.

    The variable ‘ $next_post ‘ as an argument inside the href.
    -Doesn’t work. All I get is the actual name of the variable added to the root url.

    <?php previous_post_link(‘%link’, ”);?>
    -Doesn’t work. Tried formatting the arguments for this but no luck.

    ****************************&^*^&%*&^%*&(*&(*&(
    <div class=”testclass”>

    <img src= “http://www.vikingprincess.net/wp-content/themes/tiga/images/left.gif”/&gt;

    </div>
    **************************&*%(&^%&*U^&*(^)*^

    Frustrated! 😛
    Jo

    <A HREF="<?php get_permalink($next_post->ID)?>">

    That should be:

    <A HREF="<?php echo get_permalink($next_post->ID)?>">

    Note the addition of the PHP command echo, which is necessary here because get_permalink() does not print, but only returns, the value.

    Thread Starter jojo0507

    (@jojo0507)

    Million Thanks Kafka!

    (I had called the function for populating the variable in “The Loop” which is in a different php file.
    (I thought it was a global variable.)

    But the function must be called in the same .php document as the one you are creating the image from. Otherwise, like you said, it defaults to the page you are on. Very confusing for a php newbie.
    The function should actually not be called from within The Loop as stated somewhere?

    Anyway: I’ve got it working now!
    The syntax is as follows and should be in the same php file:

    Populate variables:
    ————————–
    <?php
    $next_post = get_next_post();
    $prev_post = get_previous_post();
    ?>

    Set the image as clickable with the previous post URL:
    ————————————————————
    <div class=”testclass”>
    A HREF=”<?php echo get_permalink($prev_post->ID)?>”><img src=left.gif”/></A>
    </div>

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Previous / Next Post Problem’ is closed to new replies.