修改\wp-includes\link-template.php文件get_adjacent_post_link函数:
function get_adjacent_post_link( $format, $link, $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
if ( $previous && is_attachment() ) {
$post = get_post( get_post()->post_parent );
} else {
$post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
}
if ( ! $post ) {
$output = '';
} else {
$title = $post->post_title;
if ( empty( $post->post_title ) ) {
$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
}
/** This filter is documented in wp-includes/post-template.php */
$title = apply_filters( 'the_title', $title, $post->ID );
$date = mysql2date( get_option( 'date_format' ), $post->post_date );
$rel = $previous ? 'prev' : 'next';
$string = '<a href="' . get_permalink( $post ) . '" rel="' . $rel . '">';
$inlink = str_replace( '%title', $title, $link );
$inlink = str_replace( '%date', $date, $inlink );
//$inlink = $string . $inlink . '</a>'; //注释或删除此行
//Start-添加代码
if($previous)
{
$inlink = $string . $title .$inlink . '</a>';
}else{
$inlink = $string . $inlink . $title. '</a>';
}
//End-添加代码
$output = str_replace( '%link', $inlink, $format );
}
$adjacent = $previous ? 'previous' : 'next';
return apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post, $adjacent );
}
修改前后对比:
如标题换行显示的话,仅在原代码后添加一行代码即可。
$inlink .= "<p><a href='{$post->guid}'>{$title}</a></p>";