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
Better Adjacent Posts Links 1.0
~ 1068 downloads from this website.
Or 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_lenghtand$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_lenghtand$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', '« %title',false,'',25,'previous post: ') ?>
will give a result like this one:“previous post: « post with a title too…“
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.
Excellent! Thank you.
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.
Gijet, wordpress strips out the tags from the comments as you see (
Great, works perfectly. Really cleans-up the design, thanks.
I’ll be using this plugin on our new company website. Thank you very much. Nice work
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.
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 !)
@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.
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!
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.
This is a great plug in :)
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.
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.
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.
perfect this is what i was looking for … you rocks
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 ? ^^
This plugin is ace
its work
thanks
Thank you SO much, you just saved me a ridiculous amount of time trying to do this myself.
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
this plugins is working on single.php page but not other page. how can i worked on other pages. can anyone help me.