adjacent_post_link

Definition:
function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {}

Display adjacent post link.
Can be either next post link or previous.

Parameters

  • string $format: Link anchor format.
  • string $link: Link permalink format.
  • bool $in_same_cat: Optional. Whether link should be in a same category.
  • array|string $excluded_categories: Optional. Array or comma-separated list of excluded category IDs.
  • bool $previous: Optional, default is true. Whether to display link to previous or next post.

Defined filters

  • the_title
    apply_filters('the_title', $title, $post->ID)
  • {$adjacent}_post_link
    apply_filters( "{$adjacent}_post_link", $format, $link )

Source code

function adjacent_post_link($format, $link, $in_same_cat = false, $excluded_categories = '', $previous = true) {

	if ( $previous && is_attachment() )

		$post = & get_post($GLOBALS['post']->post_parent);

	else

		$post = get_adjacent_post($in_same_cat, $excluded_categories, $previous);



	if ( !$post )

		return;



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

	$link = str_replace('%title', $title, $link);

	$link = str_replace('%date', $date, $link);

	$link = $string . $link . '</a>';



	$format = str_replace('%link', $link, $format);



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

	echo apply_filters( "{$adjacent}_post_link", $format, $link );

393

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: