I want to create a pagenation using wp_link_pages that looks like this
Previous 3 of 20 Next
How can this be achieved?
I am using this function btw https://codex.wordpress.org/Function_Reference/wp_link_pages
I want to create a pagenation using wp_link_pages that looks like this
Previous 3 of 20 Next
How can this be achieved?
I am using this function btw https://codex.wordpress.org/Function_Reference/wp_link_pages
I don’t see a way to do this with just the standard arguments but you can do it with a filter:
function link_hack_wpse_($output,$args) {
global $page, $numpages;
$xofy = $page.' of '.$numpages;
if (1 == $page) {
$output = str_replace($args['after']," $xofy{$args['after']}",$output);
} elseif ($page == $numpages) {
$output = str_replace($args['before'],"{$args['before']}$xofy ",$output);
} else {
$output = str_replace('</a><a',"</a> $xofy <a",$output);
}
return $output;
}
add_filter('wp_link_pages','link_hack_wpse_',10,2);
$args = array(
'before' => '<p>',
'after' => '</p>',
'next_or_number' => 'next',
'separator' => '',
'nextpagelink' => __( 'Next' ),
'previouspagelink' => __( 'Previous' ),
'pagelink' => '%',
'echo' => 1
);defaults
wp_link_pages( $args );
I should note that this is very dependent upon the $args
settings. It is not going to be portable without modification.