';
echo $pagination; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}
}
/**
* Add in a previous and next functionality
*/
function nightingale_get_prev_next() {
echo '
';
}
/**
* Add in a method to go backwards and forwards between posts.
*
* @param array $args the arguments coming in to the function.
*
* @return string the output.
*/
function nightingale_the_post_navigation( $args = array() ) {
$args = wp_parse_args(
$args,
array(
'prev_text' => 'Previous:%title
',
'next_text' => 'Next:%title
',
'in_same_term' => false,
'excluded_terms' => '',
'taxonomy' => 'category',
'screen_reader_text' => __( 'Post navigation', 'nightingale' ),
)
);
$navigation = '';
$previous = get_previous_post_link(
'
',
$args['next_text'],
$args['in_same_term'],
$args['excluded_terms'],
$args['taxonomy']
);
// Only add markup if there's somewhere to navigate to.
if ( $previous || $next ) {
$navigation = $previous . $next;
}
return $navigation;
}
/**
* Filter wp_link_pages to do both next and number for post broken into multiple pages.
*/
add_filter( 'wp_link_pages_args', 'nightingale_link_pages_args_prevnext_add' );
/**
* Add prev and next links to a numbered link list
*
* @param array $args the values passed in to create the links.
*/
function nightingale_link_pages_args_prevnext_add( $args ) {
global $page, $numpages;
$args['before'] .= ''; // End pagenav links.
if ( $page - 1 ) {
// there is a previous page.
$args['before'] .= _wp_link_page( $page - 1 ) . $args['link_before'] . $args['previouspagelink'] . $args['link_after'] . '';
}
if ( $page < $numpages ) {
// there is a next page.
$args['after'] = _wp_link_page( $page + 1 ) . $args['link_before'] . $args['nextpagelink'] . $args['link_after'] . '' . $args['after'];
}
return $args;
}
/**
* Add a class to previous link in pagination
*
* @param string $format the original markup.
*/
function nightingale_posts_link__class( $format ) {
$format = str_replace( 'href=', 'class="nhsuk-pagination__link" href=', $format );
return $format;
}
add_filter( 'next_post_link', 'nightingale_posts_link__class' );
add_filter( 'previous_post_link', 'nightingale_posts_link__class' );
add_filter( 'wp_link_pages_link', 'nightingale_split_post_pagination' );
/**
* Function to add tag markup to pagination output
*
* @param string $output the original markup.
*
* @return string $output the corrected markup
*/
function nightingale_split_post_pagination( $output ) {
$output = str_replace( '"post-page-numbers current"', '"post-page-numbers current nhsuk-tag nhsuk-tag--white"', $output );
$output = str_replace( '"post-page-numbers"', '"post-page-numbers nhsuk-tag nhsuk-tag--grey"', $output );
return $output;
}