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 from the WordPress Repository.
extract, upload to the plugins folder of your wordpress install, activate. See “Usage”.
— 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 ‘|’)
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 ‘
My replacement functions anyway come with two additional variables:
$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,
$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…“