Thread Starter
baszer
(@baszer)
thanks! the downside is that it also kills the « (and not this one, but the one to the right)
Is there a way to have this:
longtit… ->
You could still place it outside your the post link, like <div class="nav-previous">«<?php previous_post_link( '%link', '« %title' ) ?></div>
Thread Starter
baszer
(@baszer)
Thanks Jeremy! This did the trick, for everyone who comes to this topic:
add the following to your function.php
function filter_shorten_linktext($linkstring,$link) {
$characters = 33;
preg_match('/<a.*?>(.*?)<\/a>/is',$linkstring,$matches);
$displayedTitle = $matches[1];
$newTitle = shorten_with_ellipsis($displayedTitle,$characters);
return str_replace('>'.$displayedTitle.'<','>'.$newTitle.'<',$linkstring);
}
function shorten_with_ellipsis($inputstring,$characters) {
return (strlen($inputstring) >= $characters) ? substr($inputstring,0,($characters-3)) . '...' : $inputstring;
}
// This adds filters to the next and previous links, using the above functions
// to shorten the text displayed in the post-navigation bar. The last 2 arguments
// are necessary; the last one is the crucial one. Saying "2" means the function
// "filter_shorten_linktext()" takes 2 arguments. If you don't say so here, the
// hook won't pass them when it's called and you'll get a PHP error.
add_filter('previous_post_link','filter_shorten_linktext',10,2);
add_filter('next_post_link','filter_shorten_linktext',10,2);
and the following on the place where you want the navigations
<div id="nav-below" class="navigation">
<div class="nav-previous">« <?php previous_post_link ( '%link', '%title' ) ?></div>
<div class="nav-next"><?php next_post_link( '%link', '%title »' ) ?> »</div>
</div>
Thread Starter
baszer
(@baszer)
aaaargh, still not perfect. Now I got the » still visible even if you are on the latest post!
Thread Starter
baszer
(@baszer)
anybody an idea how to get rit of the » when you are on the last post?
Thread Starter
baszer
(@baszer)
fixed:
<div id="nav-above" class="navigation">
<div class="nav-previous"><?php previous_post_link ( '« %link', '%title' ) ?></div>
<div class="nav-next"><?php next_post_link( '%link »', '%title' ) ?> </div>
</div>