Make wp_link_pages() filterable. Add 'separator' argument. Simplify the function logic. props obenland, brianlayman. fixes #13578.

git-svn-id: http://core.svn.wordpress.org/trunk@23653 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2013-03-08 18:33:52 +00:00
parent 39223fde2a
commit 17a24f8400
1 changed files with 45 additions and 39 deletions

View File

@ -602,15 +602,6 @@ function post_password_required( $post = null ) {
* Quicktag one or more times). This tag must be within The Loop. * Quicktag one or more times). This tag must be within The Loop.
* *
* The defaults for overwriting are: * The defaults for overwriting are:
* 'next_or_number' - Default is 'number' (string). Indicates whether page
* numbers should be used. Valid values are number and next.
* 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
* of the bookmark.
* 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
* previous page, if available.
* 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
* the parameter string will be replaced with the page number, so Page %
* generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
* 'before' - Default is '<p> Pages:' (string). The html or text to prepend to * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
* each bookmarks. * each bookmarks.
* 'after' - Default is '</p>' (string). The html or text to append to each * 'after' - Default is '</p>' (string). The html or text to append to each
@ -621,20 +612,36 @@ function post_password_required( $post = null ) {
* 'link_after' - Default is '' (string). The html or text to append to each * 'link_after' - Default is '' (string). The html or text to append to each
* Pages link inside the <a> tag. Also appended to the current item, which * Pages link inside the <a> tag. Also appended to the current item, which
* is not linked. * is not linked.
* 'next_or_number' - Default is 'number' (string). Indicates whether page
* numbers should be used. Valid values are number and next.
* 'separator' - Default is ' ' (string). Text used between pagination links.
* 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
* of the bookmark.
* 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
* previous page, if available.
* 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
* the parameter string will be replaced with the page number, so Page %
* generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
* 'echo' - Default is 1 (integer). When not 0, this triggers the HTML to be
* echoed and then returned.
* *
* @since 1.2.0 * @since 1.2.0
* @access private
* *
* @param string|array $args Optional. Overwrite the defaults. * @param string|array $args Optional. Overwrite the defaults.
* @return string Formatted output in HTML. * @return string Formatted output in HTML.
*/ */
function wp_link_pages($args = '') { function wp_link_pages( $args = '' ) {
$defaults = array( $defaults = array(
'before' => '<p>' . __('Pages:'), 'after' => '</p>', 'before' => '<p>' . __( 'Pages:' ),
'link_before' => '', 'link_after' => '', 'after' => '</p>',
'next_or_number' => 'number', 'nextpagelink' => __('Next page'), 'link_before' => '',
'previouspagelink' => __('Previous page'), 'pagelink' => '%', 'link_after' => '',
'echo' => 1 'next_or_number' => 'number',
'separator' => ' ',
'nextpagelink' => __( 'Next page' ),
'previouspagelink' => __( 'Previous page' ),
'pagelink' => '%',
'echo' => 1
); );
$r = wp_parse_args( $args, $defaults ); $r = wp_parse_args( $args, $defaults );
@ -647,35 +654,34 @@ function wp_link_pages($args = '') {
if ( $multipage ) { if ( $multipage ) {
if ( 'number' == $next_or_number ) { if ( 'number' == $next_or_number ) {
$output .= $before; $output .= $before;
for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) { for ( $i = 1; $i <= $numpages; $i++ ) {
$j = str_replace('%',$i,$pagelink); $link = $link_before . str_replace( '%', $i, $pagelink ) . $link_after;
$output .= ' '; if ( $i != $page || ! $more && 1 == $page )
if ( ($i != $page) || ((!$more) && ($page==1)) ) { $link = _wp_link_page( $i ) . $link . '</a>';
$output .= _wp_link_page($i); $link = apply_filters( 'wp_link_pages_link', $link, $i );
} $output .= $separator . $link;
$output .= $link_before . $j . $link_after;
if ( ($i != $page) || ((!$more) && ($page==1)) )
$output .= '</a>';
} }
$output .= $after; $output .= $after;
} else { } elseif ( $more ) {
if ( $more ) { $output .= $before;
$output .= $before; $i = $page - 1;
$i = $page - 1; if ( $i ) {
if ( $i && $more ) { $link = _wp_link_page( $i ) . $link_before . $previouspagelink . $link_after . '</a>';
$output .= _wp_link_page($i); $link = apply_filters( 'wp_link_pages_link', $link, $i );
$output .= $link_before. $previouspagelink . $link_after . '</a>'; $output .= $separator . $link;
}
$i = $page + 1;
if ( $i <= $numpages && $more ) {
$output .= _wp_link_page($i);
$output .= $link_before. $nextpagelink . $link_after . '</a>';
}
$output .= $after;
} }
$i = $page + 1;
if ( $i <= $numpages ) {
$link = _wp_link_page( $i ) . $link_before . $nextpagelink . $link_after . '</a>';
$link = apply_filters( 'wp_link_pages_link', $link, $i );
$output .= $separator . $link;
}
$output .= $after;
} }
} }
$output = apply_filters( 'wp_link_pages', $output, $args );
if ( $echo ) if ( $echo )
echo $output; echo $output;