Skip to content

Instantly share code, notes, and snippets.

@BronsonQuick
Created September 24, 2012 05:05
Show Gist options
  • Save BronsonQuick/3774261 to your computer and use it in GitHub Desktop.
Save BronsonQuick/3774261 to your computer and use it in GitHub Desktop.
Changes wp_link_pages to be an unordered list in WordPress
<?php /*
* Function similar to wp_link_pages but outputs an ordered list instead and adds a class of current to the current page
*/
function pico_link_pages( $args = '' ) {
$defaults = array(
'before' => '<p>' . __( 'Pages:' ), 'after' => '</p>',
'link_before' => '', 'link_after' => '',
'next_or_number' => 'number', 'nextpagelink' => __( 'Next page' ),
'previouspagelink' => __( 'Previous page' ), 'pagelink' => '%',
'echo' => 1
);
$r = wp_parse_args( $args, $defaults );
$r = apply_filters( 'wp_link_pages_args', $r );
extract( $r, EXTR_SKIP );
global $page, $numpages, $multipage, $more, $pagenow;
$output = '';
if ( $multipage ) {
if ( 'number' == $next_or_number ) {
$output .= $before;
$output .= '<ul>';
for ( $i = 1; $i < ( $numpages + 1 ); $i = $i + 1 ) {
$j = str_replace( '%', $i, $pagelink );
if ( ( $i == $page )) {
$output .= '<li class="current">';
} else {
$output .= '<li>';
}
if ( ( $i != $page ) || ( ( ! $more ) && ( $page == 1 ) ) ) {
$output .= _wp_link_page( $i );
}
$output .= $link_before . $j . $link_after;
if ( ( $i != $page ) || ( ( ! $more ) && ( $page == 1 ) ) )
$output .= '</a>';
}
$output .= '</li>';
$output .= $after;
} else {
if ( $more ) {
$output .= $before;
$i = $page - 1;
if ( $i && $more ) {
$output .= _wp_link_page( $i );
$output .= $link_before . $previouspagelink . $link_after . '</a>';
}
$i = $page + 1;
if ( $i <= $numpages && $more ) {
$output .= _wp_link_page( $i );
$output .= $link_before . $nextpagelink . $link_after . '</a>';
}
$output .= '</ul>';
$output .= $after;
}
}
}
if ( $echo )
echo $output;
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment