• well, as you know wordpress generates an id for each post.. this could be simply used to create a nice and small hack to jump to the previous post in the same page using anchors..
    go into the wordpress loop, and place this code where you want it to appear (eg. next to the date or between the post footer items..)
    <pre>
    // place it at the top of the wp loop
    // better just before the post title
    // (you should have it, anyway..)
    “>
    // calculates previous post id
    // by subtracting 1 unit
    // and gives it to the $next variable
    <?php
    $next=$id-1;
    ?&gt
    // generates a link
    // to the previous post anchor
    ” title=”go previous post”>prev
    </pre>
    an example could be seen at https://gat.blogo.net
    enjoy..

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter gat

    (@gat)

    … well, &gt, of course is >… sorry

    Hi gat, this will only work if you never post out of order.
    For example you may create a new post, but leave it in draft mode for a few days while you work on it. Meanwhile you are posting other entries.
    This would mean the chronologically, the correct order would not be the same as the id order.
    Similarly, if you delete a post then you could end up with a link to a non-existent post.
    Mike

    Thread Starter gat

    (@gat)

    Hi mike. well, yes you are right! And I’m guilty because i knew that and forgot to post it ??
    Actually, yes, if you delete a post or leave one in draft mode, you may have a broken link.. note that if your broken link is an anchor into the same page (for example href=”#hello”) the links simply doesn’t work, without giving any headache like 404 or something
    thanks mike!

    you could also use the previous|next_post() function …

    Thanks. I used the <!–more–> as I might have had I read the documentation thoroughly. The results are what I needed. Cluelessly but learning, Tim

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘previous post in the same page (not a real hack bu’ is closed to new replies.