Make WordPress Core

Changeset 23653


Ignore:
Timestamp:
03/08/2013 06:33:52 PM (12 years ago)
Author:
SergeyBiryukov
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r23639 r23653  
    603603 *
    604604 * The defaults for overwriting are:
    605  * 'next_or_number' - Default is 'number' (string). Indicates whether page
    606  *      numbers should be used. Valid values are number and next.
    607  * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
    608  *      of the bookmark.
    609  * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
    610  *      previous page, if available.
    611  * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
    612  *      the parameter string will be replaced with the page number, so Page %
    613  *      generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
    614605 * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
    615606 *      each bookmarks.
     
    622613 *      Pages link inside the <a> tag. Also appended to the current item, which
    623614 *      is not linked.
     615 * 'next_or_number' - Default is 'number' (string). Indicates whether page
     616 *      numbers should be used. Valid values are number and next.
     617 * 'separator' - Default is ' ' (string). Text used between pagination links.
     618 * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
     619 *      of the bookmark.
     620 * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
     621 *      previous page, if available.
     622 * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
     623 *      the parameter string will be replaced with the page number, so Page %
     624 *      generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
     625 * 'echo' - Default is 1 (integer). When not 0, this triggers the HTML to be
     626 *      echoed and then returned.
    624627 *
    625628 * @since 1.2.0
    626  * @access private
    627629 *
    628630 * @param string|array $args Optional. Overwrite the defaults.
    629631 * @return string Formatted output in HTML.
    630632 */
    631 function wp_link_pages($args = '') {
     633function wp_link_pages( $args = '' ) {
    632634    $defaults = array(
    633         'before' => '<p>' . __('Pages:'), 'after' => '</p>',
    634         'link_before' => '', 'link_after' => '',
    635         'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
    636         'previouspagelink' => __('Previous page'), 'pagelink' => '%',
    637         'echo' => 1
     635        'before'           => '<p>' . __( 'Pages:' ),
     636        'after'            => '</p>',
     637        'link_before'      => '',
     638        'link_after'       => '',
     639        'next_or_number'   => 'number',
     640        'separator'        => ' ',
     641        'nextpagelink'     => __( 'Next page' ),
     642        'previouspagelink' => __( 'Previous page' ),
     643        'pagelink'         => '%',
     644        'echo'             => 1
    638645    );
    639646
     
    648655        if ( 'number' == $next_or_number ) {
    649656            $output .= $before;
    650             for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
    651                 $j = str_replace('%',$i,$pagelink);
    652                 $output .= ' ';
    653                 if ( ($i != $page) || ((!$more) && ($page==1)) ) {
    654                     $output .= _wp_link_page($i);
    655                 }
    656                 $output .= $link_before . $j . $link_after;
    657                 if ( ($i != $page) || ((!$more) && ($page==1)) )
    658                     $output .= '</a>';
     657            for ( $i = 1; $i <= $numpages; $i++ ) {
     658                $link = $link_before . str_replace( '%', $i, $pagelink ) . $link_after;
     659                if ( $i != $page || ! $more && 1 == $page )
     660                    $link = _wp_link_page( $i ) . $link . '</a>';
     661                $link = apply_filters( 'wp_link_pages_link', $link, $i );
     662                $output .= $separator . $link;
    659663            }
    660664            $output .= $after;
    661         } else {
    662             if ( $more ) {
    663                 $output .= $before;
    664                 $i = $page - 1;
    665                 if ( $i && $more ) {
    666                     $output .= _wp_link_page($i);
    667                     $output .= $link_before. $previouspagelink . $link_after . '</a>';
    668                 }
    669                 $i = $page + 1;
    670                 if ( $i <= $numpages && $more ) {
    671                     $output .= _wp_link_page($i);
    672                     $output .= $link_before. $nextpagelink . $link_after . '</a>';
    673                 }
    674                 $output .= $after;
     665        } elseif ( $more ) {
     666            $output .= $before;
     667            $i = $page - 1;
     668            if ( $i ) {
     669                $link = _wp_link_page( $i ) . $link_before . $previouspagelink . $link_after . '</a>';
     670                $link = apply_filters( 'wp_link_pages_link', $link, $i );
     671                $output .= $separator . $link;
    675672            }
     673            $i = $page + 1;
     674            if ( $i <= $numpages ) {
     675                $link = _wp_link_page( $i ) . $link_before . $nextpagelink . $link_after . '</a>';
     676                $link = apply_filters( 'wp_link_pages_link', $link, $i );
     677                $output .= $separator . $link;
     678            }
     679            $output .= $after;
    676680        }
    677681    }
     682
     683    $output = apply_filters( 'wp_link_pages', $output, $args );
    678684
    679685    if ( $echo )
Note: See TracChangeset for help on using the changeset viewer.