get_adjacent_post_rel_link() – Retrieves the adjacent post relational link.

You appear to be a bot. Output may be restricted

Description

Retrieves the adjacent post relational link.

Can either be next or previous post relational link.

Usage

$string|void = get_adjacent_post_rel_link( $title, $in_same_term, $excluded_terms, $previous, $taxonomy );

Parameters

$title
( string ) optional default: %title – Optional. Link title format. Default '%title'.
$in_same_term
( bool ) optional – Optional. Whether link should be in a same taxonomy term. Default false.
$excluded_terms
( int[]|string ) optional – Optional. Array or comma-separated list of excluded term IDs. Default empty.
$previous
( bool ) optional default: 1 – Optional. Whether to display link to previous or next post. Default true.
$taxonomy
( string ) optional default: category – Optional. Taxonomy, if $in_same_term is true. Default 'category'.

Returns

string|void The adjacent post relational link URL.

Source

File name: wordpress/wp-includes/link-template.php
Lines:

1 to 51 of 51
function get_adjacent_post_rel_link( $title = '%title', $in_same_term = false, $excluded_terms = '', $previous = true, $taxonomy = 'category' ) {
  $post = get_post();
  if ( $previous && is_attachment() && $post ) {
    $post = get_post( $post->post_parent );
  } else {
    $post = get_adjacent_post( $in_same_term, $excluded_terms, $previous, $taxonomy );
  }

  if ( empty( $post ) ) {
    return;
  }

  $post_title = the_title_attribute(
    array(
      'echo' => false,
      'post' => $post,
    )
  );

  if ( empty( $post_title ) ) {
    $post_title = $previous ? __( 'Previous Post' ) : __( 'Next Post' );
  }

  $date = mysql2date( get_option( 'date_format' ), $post->post_date );

  $title = str_replace( '%title', $post_title, $title );
  $title = str_replace( '%date', $date, $title );

  $link  = $previous ? "<link rel='prev' title='" : "<link rel='next' title='";
  $link .= esc_attr( $title );
  $link .= "' href='" . get_permalink( $post ) . "' />\n";

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

  
/**
 * Filters the adjacent post relational link.
 *
 * The dynamic portion of the hook name, `$adjacent`, refers to the type
 * of adjacency, 'next' or 'previous'.
 *
 * Possible hook names include:
 *
 *  - `next_post_rel_link`
 *  - `previous_post_rel_link`
 *
 * @since 2.8.0
 *
 * @param string $link The relational link.
 */
  return apply_filters( "{$adjacent}_post_rel_link", $link );
}
 

 View on GitHub View on Trac