Previous Post Link – V2 series ( deprecated )

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

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

Used on single post permalink pages, this template tag displays a link to the previous 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 previous_post_link. However this offer a very limited capability and there is no way to receive the previous post within a taxonomy term and using the custom defined order.

An improvement for that function is previous_post_type_link

Arguments:

previous_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 '&laquo; %link'.

$link(string) Link text to display. Defaults to previous 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 previous post link using the custom defined order from within the Archive (all posts).
previous_post_type_link( ‘%link’, __( ‘<span>&larr;</span> Previous’, ‘twentyeleven’ ), TRUE);

Display the previous post link using the default WordPress order:
previous_post_type_link( ‘%link’, __( ‘<span>&larr;</span> Previous’, ‘twentyeleven’ ), FALSE);

Display the previous post link using the order specified within categories, through term name ‘News Category’ with id 5
previous_post_type_link( ‘%link’, __( ‘<span>&larr;</span> Previous’, ‘twentyeleven’ ), TRUE, ‘5’, ‘category’ );

Display the previous post link using the order specified within taxonomy ‘Movies’, within term name ‘Titanic’ with id 10
previous_post_type_link( ‘%link’, __( ‘<span>&larr;</span> Previous’, ‘twentyeleven’ ), TRUE, ’10’, ‘movies’ );

Return the previous post link using default order from taxonomy ‘Features’ within term ‘Design’
previous_post_type_link( ‘%link’, __( ‘<span>&larr;</span> Previous’, ‘twentyeleven’ ), FALSE, ’15’, features’ );