Next Post Link – V2 Series

Share on FacebookTweet about this on TwitterShare on Google+Share on LinkedInPrint this page

This function format has been deprecated, see this post instead Next Post Link for v3 series.

Used on single post permalink 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.

The default WordPress function for this is next_post_link. However this is a very limited procedure and there is no way to receive the next post within a taxonomy term and using the custom defined order.

An improvement for that function is next_post_type_link

Arguments:
next_post_type_link($format, $link, $use_custom_order, $term_id, $taxonomy);

Parameters
$format
(string) Format string for the link. This is where to control what comes before and after the link. ‘%link’ in string will be replaced with whatever is declared as ‘link’ (see next parameter). ‘Go to %link’ will generate “Go to <a href=…” Put HTML tags here to style the final results. Defaults to ‘« %link’.

$link
(string) Link text to display. Defaults to next post’s title (‘%title’).

$use_custom_order
(boolean) Use the custom defined order

$term_id
(int) Specify the term id from where the order will apply

$taxonomy
(string) Specify the taxonomy name for the $term_id

Examples

Display the next post link using the custom defined order from within the Archive (all posts).
next_post_type_link( ‘%link’, __( ‘ Next’, ‘twentyeleven’ ), TRUE);

Display the next post link using the default WordPress order:
next_post_type_link( ‘%link’, __( ‘ Next’, ‘twentyeleven’ ), FALSE);

Display the next post link using the order specified within categories, through term name ‘News Category’ with id 5
next_post_type_link( ‘%link’, __( ‘ Next’, ‘twentyeleven’ ), TRUE, ‘5’, ‘category’ );

Display the next post link using the order specified within taxonomy ‘Movies’, within term name ‘Spiderman’ with id 10
next_post_type_link( ‘%link’, __( ‘ Next’, ‘twentyeleven’ ), TRUE, ’10’, ‘movies’ );

Return the next post link using default order from taxonomy ‘Features’ within term ‘App’
next_post_type_link( ‘%link’, __( ‘ Next’, ‘twentyeleven’ ), FALSE, ’15’, features’ );