我只想过滤previous_post_link
和next_post_link
. 这样,您的模板保持干净,您可以将额外的逻辑移动到functions.php
.
示例,未测试:
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=\'$url\' rel=\'$rel\'>$text</a></h5>
</div>
<div class=\'title2\'>
<h5><a href=\'$url\' rel=\'$rel\'>$title</a></h5>
</div>
</div>";
}