next_post_link()

This WordPress function requires the CPT-onomy class.

Description

Used on single post pages, this template tag displays a link to the next post which exists in chronological order from the current post.

This tag must be used in The Loop.

Usage

$cpt_onomy->next_post_link( 						string
						$format
						, 						string
						$link
						, 						bool
						$in_same_cpt_onomy
						, 						string|array
						$excluded_term_ids
						, 						string
						$cpt_onomy
						 );

Parameters

$format (string) (required)
Default: %link »
Format string for the link. Must define this parameter or else the link will not be printed.

$link (string) (required)
Default: %title
Link text to display. Must define this parameter if you do not want the link text to be NULL. The function will still print the <a></a> if left undefined. Default is '%title' which prints the post's title.

$in_same_cpt_onomy (boolean) (optional)
Default: false
Indicates whether next post must be within the same CPT-onomy as the current post. Must provide the CPT-onomy.

$excluded_term_ids (string|array) (optional)
Default: none
CPT-onomy terms ID(s) from which the next post should not be listed.

$cpt_onomy (string) (optional)
Default: none
Name of the CPT-onomy for use with $in_same_cpt_onomy.

Examples

Default usage:

<?php next_post_link(); ?>

Bold post title:

<?php next_post_link( '<strong>%link</strong>' ); ?>

Next post within the 'actors' CPT-onomy:
Note: You must define $format and $link.

<?php
global $cpt_onomy;
$cpt_onomy->next_post_link( '%link', '%title', true, '', 'actors' );
?>

Within the 'actors' CPT-onomy, excluding one term (id):
Note: You must define $format and $link.

<?php
global $cpt_onomy;
$cpt_onomy->next_post_link( '%link', '%title', true, '13', 'actors' );
?>

Notes

  • Since 1.0.2

WordPress Codex

For more information, refer to the WordPress codex.