| 649 | | $output = ''; |
| 650 | | if ( $multipage ) { |
| 651 | | if ( 'number' == $next_or_number ) { |
| 652 | | $output .= $before; |
| 653 | | for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) { |
| 654 | | $j = str_replace('%',$i,$pagelink); |
| 655 | | $output .= ' '; |
| 656 | | if ( ($i != $page) || ((!$more) && ($page==1)) ) { |
| 657 | | $output .= _wp_link_page($i); |
| 658 | | } |
| 659 | | $output .= $link_before . $j . $link_after; |
| 660 | | if ( ($i != $page) || ((!$more) && ($page==1)) ) |
| 661 | | $output .= '</a>'; |
| | 658 | if ( ( $i != $page ) || ( !$more && 1 == $page ) ) { |
| | 659 | $link = '<a href="' . esc_url( get_multipage_link( $i ) ) . '">' . $link . '</a>'; |
| 663 | | $output .= $after; |
| 664 | | } else { |
| 665 | | if ( $more ) { |
| 666 | | $output .= $before; |
| 667 | | $i = $page - 1; |
| 668 | | if ( $i && $more ) { |
| 669 | | $output .= _wp_link_page($i); |
| 670 | | $output .= $link_before. $previouspagelink . $link_after . '</a>'; |
| 671 | | } |
| 672 | | $i = $page + 1; |
| 673 | | if ( $i <= $numpages && $more ) { |
| 674 | | $output .= _wp_link_page($i); |
| 675 | | $output .= $link_before. $nextpagelink . $link_after . '</a>'; |
| 676 | | } |
| 677 | | $output .= $after; |
| 678 | | } |
| | 661 | $link = apply_filters( 'wp_link_pages_link', $link, $i ); |
| | 662 | $output .= ' ' . $link; |
| | 663 | } |
| | 664 | $output .= $after; |
| | 665 | } elseif ( $more ) { |
| | 666 | $output .= $before; |
| | 667 | $i = $page - 1; |
| | 668 | if ( $i ) { |
| | 669 | $link = '<a href="' . esc_url( get_multipage_link( $i ) ) . '">' .$link_before. $previouspagelink . $link_after . '</a>'; |
| | 670 | $output .= apply_filters( 'wp_link_pages_link', $link, $i ); |
| | 671 | } |
| | 672 | $i = $page + 1; |
| | 673 | if ( $i <= $numpages ) { |
| | 674 | $link = '<a href="' . esc_url( get_multipage_link( $i ) ) . '">' . $link_before. $nextpagelink . $link_after . '</a>'; |
| | 675 | $output .= apply_filters( 'wp_link_pages_link', $link, $i ); |
| 688 | | /** |
| 689 | | * Helper function for wp_link_pages(). |
| 690 | | * |
| 691 | | * @since 3.1.0 |
| 692 | | * @access private |
| 693 | | * |
| 694 | | * @param int $i Page number. |
| 695 | | * @return string Link. |
| 696 | | */ |
| 697 | | function _wp_link_page( $i ) { |
| 698 | | global $post, $wp_rewrite; |
| 699 | | |
| 700 | | if ( 1 == $i ) { |
| 701 | | $url = get_permalink(); |
| 702 | | } else { |
| 703 | | if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) ) |
| 704 | | $url = add_query_arg( 'page', $i, get_permalink() ); |
| 705 | | elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID ) |
| 706 | | $url = trailingslashit(get_permalink()) . user_trailingslashit("$wp_rewrite->pagination_base/" . $i, 'single_paged'); |
| 707 | | else |
| 708 | | $url = trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged'); |
| 709 | | } |
| 710 | | |
| 711 | | return '<a href="' . esc_url( $url ) . '">'; |
| 712 | | } |
| 713 | | |