这是我用来替代的wp_link_pages()
. 它不使用单独的类,而是为当前页面使用另一个元素,因为页面不应该链接到当前URL。
/**
* Modification of wp_link_pages() with an extra element to highlight the current page.
*
* @param array $args
* @return void
*/
function t5_numerical_link_pages( $args = array () )
{
$defaults = array(
\'before\' => \'<p>\' . __( \'Pages:\', \'t5_theme\' )
, \'after\' => \'</p>\'
, \'link_before\' => \'\'
, \'link_after\' => \'\'
, \'pagelink\' => \'%\'
, \'echo\' => 1
// element for the current page
, \'highlight\' => \'b\'
);
$r = wp_parse_args( $args, $defaults );
$r = apply_filters( \'wp_link_pages_args\', $r );
extract( $r, EXTR_SKIP );
global $page, $numpages, $multipage, $more, $pagenow;
if ( ! $multipage )
{
return;
}
$output = $before;
for ( $i = 1; $i < ( $numpages + 1 ); $i++ )
{
$j = str_replace( \'%\', $i, $pagelink );
$output .= \' \';
if ( $i != $page || ( ! $more && 1 == $page ) )
{
$output .= _wp_link_page( $i ) . "{$link_before}{$j}{$link_after}</a>";
}
else
{ // highlight the current page
// not sure if we need $link_before and $link_after
$output .= "<$highlight>{$link_before}{$j}{$link_after}</$highlight>";
}
}
$echo and print $output . $after;
return $output . $after;
}