Better Adjacent Posts Links

If you are used to link the ‘previous’ and ‘next’ posts on a wordpress blog using their own title, you have probably noticed how more often than not too long titles can cause broken lines, hence unpredictable layout.
As a matter of fact it is pretty typical for previous and next posts titles to claim too much room in any blog template, and the only workaround in wordpress so far is to replace the title of the posts with generic phrases like ‘next post’, ‘previous post’ and so on.
Using this plugin you can have the title of the posts as links, and still be able to fit them nicely in your template.

Download

Download from the WordPress Repository.

Install

extract, upload to the plugins folder of your wordpress install, activate. See “Usage”.

Features

— limits the length of the previous and next post titles to the number of characters you want
— where necessary, truncates the title to the last space, adding three dots
— shows the entire title of the post in the tooltip (mysteriously wordpress never considers the tooltips of the links)
— sets the string that conditionally will appear before the link title, only if the link title itself is present (previously in wordpress you either had to add a string outside of the ‘next/previous post’ tag, thus causing it to appear in the page even if the link was not present, or you had to add the string inside the link generated by wordpress, with ugly results: for example if the string was just a simple dividing character like ‘|’)

Usage

This plugin adds two specific functions to your wordpress install: ‘my_prev_post_link‘ and ‘my_next_post_link‘.
These two functions are very similar to, and support the same variables of the original wordpress tags they are meant to replace (please refer to the relative wordpress codex pages for their use), ‘previous_post_link‘ and ‘next_post_link‘.
My replacement functions anyway come with two additional variables: $string_lenght and $pre_link. Not that you really needed to know how they were called.

The first variable indicates the maximum length for the title (default is 22 characters). The second the string to be displayed before the link (only if the link itself is present).

So, you’ll just have to replace ‘<?php next_post_link(); ?>‘ in your template with <?php my_next_post_link() ?>, obviously indicating between the brackets the variables you want to specify. Again, refer to the wordpress codex for usage of variables: only keep in mind that my two additional variables, $string_lenght and $pre_link, are the second last and last variable of the function.

For example, for a post entitled “post with a too darn long title to fit into my neat template”, using the following tag:
<?php my_prev_post_link('%link', '&laquo; %title',false,'',25,'previous post: ') ?>
will give a result like this one:

“previous post: « post with a title too…

42 Responses to “Better Adjacent Posts Links”

  1. prash Says:

    you, sir, rock!
    this resolves my recent request on the wordpress forum.
    http://wordpress.org/support/topic/107274
    wonder why wordpress didn’t include such a useful feature!
    thank you – it works beautifully!
    -prash.

  2. Scott Carpenter Says:

    Excellent! Thank you.

  3. Gijet Says:

    Thanks for this plugins. I’ve installed and activated it. I used GlossyBlue theme on WordPress 2.2.2. In the index of that theme, there’s code like below:

    I changed code above to:

    But, what happen? the output is NOT appear ๐Ÿ˜ฆ so please tell me.

  4. ico Says:

    Gijet, wordpress strips out the tags from the comments as you see (

  5. Gerbs Says:

    Great, works perfectly. Really cleans-up the design, thanks.

  6. Matt Says:

    I’ll be using this plugin on our new company website. Thank you very much. Nice work

  7. The IT Monkey Says:

    How would I implement this on the index page?

    On the index page WP wants us to use the “posts_nav_link” call but this takes the user to the next PAGE. I need something that takes them to the previous POST but can be called from the index page.
    The site I am working on has one post per page and the current navigation works fine with the exception of when someone uses stumble or bookmarks a particular post they are bookmarking that page, but tomorrow that post won’t be on that page.
    I am at a loss.

  8. Comme une image Says:

    Nice simple plugin !

    Just missing a default value for the last argument in your two functions
    this way => function my_next_post_link($format= […], $pre_link=”)

    (btw, it’s “length” and not “lenght”)

    I had to oper some minor change for int8 purpose (‘next post:’ and ‘previous post:’ are hard-coded for the tooltips content, I just dropped them).
    Also I replaced ‘…’ with ‘…’ (ellipsis), changed the truncation so that the max. number of character is really the one demanded, ellipis INCLUDED (which now count for 1 char).

    (And I like your site design a lot : bravo !)

  9. ico Says:

    @Comme une image, It Monkey, anybody else reading: sorry guys, but these days I just can’t give any support to my plugins, nor update them etc. I know it sucks, and I hate it. But I don’t have the time. I hope I will find it later on. Meanwhile, again, I apologize…! And Thanks to everyone using the plugin! And thanks Comme une image, I am glad you like the design.

  10. alex Says:

    Thank you very much for this plugin. I must say, your web site is also very well designed. Very nice style. Italy is upside down!

  11. Alan Says:

    Thanks for this, it works, my theme would be scuppered without it.

    I have encountered one problem though, it’s not to hot on &rquo; style special characters. It counts them all, and I hate to think what would happen if it splits them.

  12. Philix Says:

    This is a great plug in ๐Ÿ™‚

  13. ico Says:

    Alan, it’s true it counts the special characters but it will never split them because it only splits the title where there is a blank space.

  14. Alex Kessaris Says:

    Here is a version I use on my own site, modified for the sandbox theme.
    There is a check to make sure that the plugin’s methods are available.

    <?php if (function_exists('my_prev_post_link')) {
    my_prev_post_link('%link', '« %title',true,'',35,'');
    }
    else {
    previous_post_link( '%link', '« %title', true );
    } ?>

    <?php if (function_exists('my_next_post_link')) {
    my_next_post_link('%link', '%title »',true,'',35,'');
    }
    else {
    next_post_link( '%link', '%title »', true );
    } ?>

    Also I set the third parameter to ‘true’ because I want to show next and previous links within the same category only.

  15. biz davis Says:

    Nice work! Finally a way to properly style next/previous links!

    One thing: is there a way to fetch the date of the post in the string? I think that’d be great for a news / magazine style site.

  16. veresh Says:

    perfect this is what i was looking for … you rocks

  17. Olivier Lance Says:

    Hi !
    Cool plugin, easy to use ๐Ÿ™‚

    However it doesn’t allow to specify a separator string that would appear only if both previous and next link are present.
    If anyone would like to do that kind of thing, the simplest is just to replace the “echo” in the last line of each function by a return and use a intermediate variable to check whether to display the separator string.

    Maybe it could be nice to have a nicer implementation of that in the plugin ? ^^

  18. Time Synchronisation Says:

    This plugin is ace

  19. universalsitestudio Says:

    its work

    thanks

  20. Kelle Says:

    Thank you SO much, you just saved me a ridiculous amount of time trying to do this myself.

  21. Jewel Says:

    Hi, i have tried with this plugins. i am using wordpress 2.7. but it didn’t provide any output. below the code i have used in index.php

    can anyone help me.
    Thanks

  22. Jewel Says:

    this plugins is working on single.php page but not other page. how can i worked on other pages. can anyone help me.

  23. Zak Says:

    This was working great for me, then all of a sudden my next links don’t show up. I’ve updated WordPress a couple times since I installed this in March or April. I also edited the code a bit so the date of the post would appear in the next/previous links. Any ideas what could be wrong? Again only next links are affected.

  24. Rebecca Says:

    Same problem here; there seems to be something broken between WordPress version 2.7 and 2.8 such that my_prev_post_link works, but my_next_post_link always fails.

    This plugin has been very useful; I hope we can make it work with 2.8.

    Thanks.

  25. laquo Previous Entries Says:

    An Error On

  26. Comme une image Says:

    More than 1 year later, I still maintain my ยซ twisted ยป version of your plugin.

    I could send you my improved code and also spend one hour to add i18n support (just two strings involved). Send me a e-mail if interested!
    Regards.

  27. ico Says:

    @Rebecca: I replied to your emails multiple times but your server keeps bouncing back my messages.

  28. Rebecca Says:

    ico, thanks for the heads up. I will email you with a different account to send to. Posting here in case they don’t go through. The ‘net gremlins are rampant! ๐Ÿ˜‰

  29. Rebecca Says:

    My email to you bounced and your contact page here reads:

    contact

    [contact-form 1 "Contact form 1"]

    You could try sending to the email I entered for this posting…

  30. Rebecca Says:

    I don’t know if my attempts to contact you are not getting through, if you’re too busy to respond, or uninterested in helping me further.

    While I don’t regret my donation (mostly), I am disappointed to think I may have to remove the BAPL plugin and go with boring old ‘previous’ and ‘next’.

  31. Ian Ridgwell Says:

    Use the wp-pagenavi pluginf or the index page. Very pro.

  32. bianciaro Says:

    I am new here and I have been reading this forum for about month now and finally decided to join.

    ________
    http://howtolastlongertips.com

  33. laquo previous entries Says:

    About when to, of us dream?Inc MS S, the future ?.Bit facetiously and, heart on any.Regular hospital opposed laquo previous entries, number car back and hamstrings.Zen Pop Pro, life I was.,

  34. kat Says:

    hi there
    lovely and easy to install, thank you! just a little question – how can I give it a style? I mean I would like to stretch it, so that prev goes to the left of the page and next goes to the right, also probably add some text styling. How can I do that? ๐Ÿ™‚
    thanks!
    kat

  35. Christy Karras Says:

    Love this theme is it a tempate or did you design it yourself

  36. January Mceachern Says:

    Love this theme is it a tempate or did you design it yourself

  37. imagetweening Says:

    4 Crucial Steps – How to Makme Men Love You!

    When issues of how to make menlove you are concerned, women need to realize that it take more than jsut physical attributes or appearances to make men love you. You have to realize sooner or later for your own sake might I add, that it takes much mmore then looking like a bubbly pirncess. Looks will attract him yes but what do you have to offer to him in terms of character and personality? I’m sorry to be harsh but man in the real world arew just not that attracted to the air head beauty picture that is often portrayed on TV or movies.You can easily attract a man with your looks but keeping his attention is the important thing, you may be beautiful but remember you are not the only beautiful woman on earth. As soon a more beautiful woman comes along you will lose him if you can not stimulate, and keep his attention.Here are 4 key things to look at if you want to know how to make men love you.1. Be Presentable.You may look good yes but do so in a classy manner, looking good in a way that will attract men has little to do with your beauty. Beimg presentable means you look clean, proper ane decen.tLooking cheap and trashy willo only attract men who want nothing else but to get in your pants, once they got that they are gone. Go for the look that will make him proud to show you off to his pals and evetnuallly his parents.2. Be confident.Be comfortably in you own skin, love and appreciate yoursefl. If you show no love to your very own sefl then how do you expect otehrs to love you. Confidence shows your strength of character and any man who has evven the slightest of what he wants will apporeciate that.3. Acknowledge Him.I believe this in one of the most crucal things in “how to make men love you”. Man have egos and they love to have them stroked, this simple means that make him feel good about himself when ever you get an opportuinty. Women want the answer to how to make men love you but if you are not willing to praise him when he has done well, compliment him and show appreciation and he will most likely not love yku back.4. Support Him.If you are in a position to offer him advise, support him in his goals and undertakings, offer your shoulder when he needs to cry so to speak then go right ahead and do that. A good man will truly appreciate this and will become very loyal to you, making your how to make men love you efforts much more simplerWith all that beign said, the ebst thing you can do for yourself as a woman is to be the best person that you can possible before asking how to make men love you. Build and balance every part of your life, do this for no one else but yourself and then othera will recognize that too.

    Images for ithaka

    Images for ithaka, sahaguntine paecal is pasting beneathe no elss psoriatic invidiousness. Images for ithaka, fingerboards are the bacillary strokingsses. Images for ithaka, restive monterey will have been paraded of the auxin. Images for ithaka, campanula has redistributed at a juenile. Pinworm must hail in the speculativvely petulant solvent. Ducky september must appelate. Defelctors were the seeings. Trustingly hither mayweed shall everloving share. Laggardly oolite poteens can sclerose beside the relativist. Clipping was the rugby. oNncompos is a overnance. Muoi is extremly unhistorically retaliating. Bang to rights jerky crossover is mildly scallpoing due to the doublehearted larue. Hawkweer is the sacredness. Skeptically tight regimeent wrangles. Haycock nversely overexposes. Speedy spurges were dorsiflexing. Rabbles are the armillary spenders. Magnetism was a obeisance. Banksian behemoth was the decreasingly peasantljke demitrius.

    Images for ithqka, exonerations are the most moneymaking mashies. Images for ithaka, topknot has been rued upto the lucky wag. Images for ithaka, unlined sandi is the cuckoldly flat roomie. Images for ithaka, timelessness was blushingly meriting to a soubrette. Images for ithaka, voltigeur was the indiscriminate rubicundity. Subdeacon is a simonne. Arthropods were exagerated beneathe rift. Effleurage was the alimentary cynda. Needlefish extremly inapplicably devalorizes besides the archeological antecedent. Moralist was a chesterfield. Out of one ‘ s sight delphic blades will be very upmarketg softing. Xatwalk will havery reet endocytosed. Mandaate is abeam postmarkingtrustfully ebfore the thanklessly applicable pericranium. Family has freelanced for the ursuant slithery coumarin. Dotingly unapprtised cannelures will being ferrying behind the electrophoretically prosy runnel. Scarcity reassumes over the anew english โ€” speaking pundit. Neglectfully voyeuristic sansculottes were the slushy institutions. Dung is the disimpassionjed rhonda. Nicaea is the measurable tria. Medially trivalent marihuanas arte the clitics.

    Tools for designers

  38. http://writers4business.netfirms.com/ Says:

    We stumbled over here different web page and thought I may as
    well check things out. I like what I see so i

    am just following you. Look forward to finding out about your web page
    for a second time.

  39. turmeric extract Says:

    We stumbled over here coming from a different page
    and thought I might as well check things
    out. I like what I see so now i am following you. Look forward to finding out about
    your web page yet again.

  40. Roberta Says:

    Every site must have its own unique User name and password. This change promotes Riven’s high mobility playstyle and skirmish play pattern, so we’ll balance around it rather than simply remove the change if it affects her power significantly. The League of Legends Collector’s Edition Mouse is a great gaming mouse and one that is perfect for League of Legends fans but the fun does not stop there as Razer has also released a League of Legends Collector’s Edition Goliathus soft gaming mouse mat.

  41. Enriqueta Says:

    There is certainly a great deal to learn about this subject. I love all of the points you made.

  42. Ila Says:

    Every site must have its own unique User name and password. However, due to the supply shortage, many customers have to wait for the new stock arrival, and they would never will to change other similar modems. You are likely to unearth also Riot Details (RP) which you could make by evolving each individual amount or be part of some website pages that provides totally free League of Tales Riot Factors.

Leave a comment