next_post_link() doesn’t give you the opportunity to add a title attribute to the link it generates. You can only control the link text and what comes before and after the link, not what’s inside the anchor tag.
There’s two obvious ways to get around this. One is to hook the ‘next_post_link’ filter and use PHP string functions to insert a title attribute before the closing ‘>’ of the anchor tag. You get the title from the $post object passed as the 4th parm to your filter callback.
The other would be to use get_adjacent_post() to get the next $post object and construct the entire HTML anchor/href/title attribute/link text string yourself, then echo it out.
i’am a bit confused.. on this page: they pull the post title right?:
<?php previous_post_link('« « %', '', 'yes'); ?>
| <?php next_post_link('% » » ', '', 'yes'); ?>
so i thought.. i combine that one with mine, but that’s a no-go?..
Yes, they pull the title as link text, but not for the title attribute, the HTML looks like this:
<a href='{$permalink}'>{$title}</a>
My understanding is you want this:
<a href='{$permalink}' title='{$title}'>{$title}</a>
Yes? It’s this part that is not possible AFAICT: title='{$title}'
Maybe I’m wrong, but I believe you need to work it as I first described to get the hover text to be something. There is one other way, by using javascript, but passing the title to javascript is just as convoluted as my first two solutions! I personally would use the get_adjacent_post() approach.
wow.. more complicated than i thought 😉
do mean something they use here ?
<?php $prev_post = get_adjacent_post( true, '', true, 'taxonomy_slug' ); ?>
<?php if ( is_a( $prev_post, 'WP_Post' ) ) { ?>
<a href="<?php echo get_permalink( $prev_post->ID ); ?>"><?php echo get_the_title( $prev_post->ID ); ?></a>
<?php } ?>
thnx