Display adjacent post link.

Can be either next post link or previous.

Signature

adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true )
format
 (string) Link anchor format.
link
 (string) Link permalink format.
in_same_cat
 (boolean) Optional. Whether link should be in a same category.
Default: false
excluded_categories
 (array|string) Optional. Array or comma-separated list of excluded category IDs.
Default: ''
previous
 (boolean) Optional, default is true. Whether to display link to previous or next post.
Default: true

Return

(void)

Source

function adjacent_post_link( $format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true ) {
	if ( $previous && is_attachment() )
		$post = get_post( get_post()->post_parent );
	else
		$post = get_adjacent_post( $in_same_cat, $excluded_categories, $previous );

	if ( ! $post ) {
		$output = '';
	} else {
		$title = $post->post_title;

		if ( empty( $post->post_title ) )
			$title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );

		$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>';

		$output = str_replace( '%link', $inlink, $format );
	}

	$adjacent = $previous ? 'previous' : 'next';

	echo apply_filters( "{$adjacent}_post_link", $output, $format, $link, $post );
}
WP Trac GitHub Bitbucket

Link here