I would just filter previous_post_link
and next_post_link
. This way, your template stays clean, and you move the extra logic to the functions.php
.
Example, not tested:
add_filter( 'previous_post_link', 'filter_single_post_pagination', 10, 4 );
add_filter( 'next_post_link', 'filter_single_post_pagination', 10, 4 );
function filter_single_post_pagination( $output, $format, $link, $post )
{
$title = get_the_title( $post );
$url = get_permalink( $post->ID );
$text="Read previous";
$class="prev-post";
$rel="prev";
if ( 'next_post_link' === current_filter() )
{
$text="Read next";
$class="next-post";
$rel="next";
}
return "<div class="$class">
<div class="title1">
<h5><a href="https://wordpress.stackexchange.com/questions/118697/$url" rel="$rel">$text</a></h5>
</div>
<div class="title2">
<h5><a href="https://wordpress.stackexchange.com/questions/118697/$url" rel="$rel">$title</a></h5>
</div>
</div>";
}