Make WordPress Core

Ticket #13578: post_template-wp_link_pages.diff

File post_template-wp_link_pages.diff, 7.5 KB (added by brianlayman, 13 years ago)

Code and comment changes to fix the functionality of wp_link_pages

  • post-template.php

     
    536536 * Quicktag one or more times). This tag must be within The Loop.
    537537 *
    538538 * The defaults for overwriting are:
     539 * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
     540 *      each bookmarks.
     541 * 'after' - Default is '</p>' (string). The html or text to append to each
     542 *      bookmarks.
     543 * 'link_before' - Default is '' (string). The html or text to prepend to each
     544 *      Pages link inside the <a> tag.
     545 * 'link_after' - Default is '' (string). The html or text to append to each
     546 *      Pages link inside the <a> tag.
    539547 * 'next_or_number' - Default is 'number' (string). Indicates whether page
    540548 *      numbers should be used. Valid values are number and next.
    541549 * 'nextpagelink' - Default is 'Next Page' (string). Text for link to next page.
    542550 *      of the bookmark.
     551 * 'separator' - Default is ' ' (string). Text used only between numbers.
    543552 * 'previouspagelink' - Default is 'Previous Page' (string). Text for link to
    544553 *      previous page, if available.
    545554 * 'pagelink' - Default is '%' (String).Format string for page numbers. The % in
    546555 *      the parameter string will be replaced with the page number, so Page %
    547556 *      generates "Page 1", "Page 2", etc. Defaults to %, just the page number.
    548  * 'before' - Default is '<p> Pages:' (string). The html or text to prepend to
    549  *      each bookmarks.
    550  * 'after' - Default is '</p>' (string). The html or text to append to each
    551  *      bookmarks.
    552  * 'link_before' - Default is '' (string). The html or text to prepend to each
    553  *      Pages link inside the <a> tag.
    554  * 'link_after' - Default is '' (string). The html or text to append to each
    555  *      Pages link inside the <a> tag.
     557 * 'echo' - Default is 1 (integer). When not 0, this triggers the text to be
     558 *              echoed as well as returned.
    556559 *
    557560 * @since 1.2.0
    558561 * @access private
     
    562565 */
    563566function wp_link_pages($args = '') {
    564567        $defaults = array(
    565                 'before' => '<p>' . __('Pages:'), 'after' => '</p>',
    566                 'link_before' => '', 'link_after' => '',
    567                 'next_or_number' => 'number', 'nextpagelink' => __('Next page'),
    568                 'previouspagelink' => __('Previous page'), 'pagelink' => '%',
     568                'before' => '<p>' . __('Pages:'),
     569                'after' => '</p>',
     570                'link_before' => '',
     571                'link_after' => '',
     572                'next_or_number' => 'number',
     573                'nextpagelink' => __('Next page'),
     574                'separator' => ' ',
     575                'previouspagelink' => __('Previous page'),
     576                'pagelink' => '%',
    569577                'echo' => 1
    570578        );
    571579
     
    581589                        $output .= $before;
    582590                        for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
    583591                                $j = str_replace('%',$i,$pagelink);
    584                                 $output .= ' ';
     592                                if ($output != $before) {
     593                                        $output .= $separator;
     594                                }
    585595                                if ( ($i != $page) || ((!$more) && ($page==1)) ) {
    586596                                        if ( 1 == $i ) {
    587                                                 $output .= '<a href="' . get_permalink() . '">';
     597                                                $output .= '<a class="pag_nav_num pag_nav_first" href="' . get_permalink() . '">';
    588598                                        } else {
    589599                                                if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
    590                                                         $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">';
     600                                                        $output .= '<a  class="pag_nav_num" href="' . add_query_arg('page', $i, get_permalink()) . '">';
    591601                                                elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
    592                                                         $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
     602                                                        $output .= '<a  class="pag_nav_num" href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
    593603                                                else
    594                                                         $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
     604                                                        $output .= '<a  class="pag_nav_num' . ($i >= $numpages ? ' pag_nav_last':'')  . '" href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
    595605                                        }
    596 
     606                                } else {
     607                                        $output .= '<span class="pag_nav_num pag_nav_current' . ($i <= 1 ? ' pag_nav_first':($i >= $numpages ? ' pag_nav_last':''))  . '">';
    597608                                }
    598609                                $output .= $link_before;
    599610                                $output .= $j;
    600611                                $output .= $link_after;
    601                                 if ( ($i != $page) || ((!$more) && ($page==1)) )
     612                                if ( ($i != $page) || ((!$more) && ($page==1)) ) {
    602613                                        $output .= '</a>';
     614                                } else {
     615                                        $output .= '</span>';
     616                                }
    603617                        }
    604618                        $output .= $after;
    605619                } else {
    606620                        if ( $more ) {
    607621                                $output .= $before;
    608622                                $i = $page - 1;
    609                                 if ( $i && $more ) {
     623                                if ( ($i > 0) && $more && ($previouspagelink != "")) {
    610624                                        if ( 1 == $i ) {
    611                                                 $output .= '<a href="' . get_permalink() . '">';
     625                                                $output .= '<a class="pag_nav_prev pag_nav_first" href="' . get_permalink() . '">' . $link_before . $previouspagelink . $link_after . '</a>';
    612626                                        } else {
    613627                                                if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
    614                                                         $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">';
     628                                                        $output .= '<a class="pag_nav_prev" href="' . add_query_arg('page', $i, get_permalink()) . '">' . $link_before . $previouspagelink . $link_after . '</a>';
    615629                                                elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
    616                                                         $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
     630                                                        $output .= '<a class="pag_nav_prev" href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
    617631                                                else
    618                                                         $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
     632                                                        $output .= '<a class="pag_nav_prev" href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $previouspagelink . $link_after . '</a>';
    619633                                        }
    620                                         $output .= $link_before. $previouspagelink . $link_after . '</a>';
    621634                                }
    622635                                $i = $page + 1;
    623                                 if ( $i <= $numpages && $more ) {
     636                                if ( ($i <= $numpages) && $more && ($nextpagelink != "")) {
    624637                                        if ( 1 == $i ) {
    625                                                 $output .= '<a href="' . get_permalink() . '">';
     638                                                $output .= '<a class="pag_nav_next first" href="' . get_permalink() . '">' . $link_before . $nextpagelink . $link_after . '</a>';
    626639                                        } else {
    627640                                                if ( '' == get_option('permalink_structure') || in_array($post->post_status, array('draft', 'pending')) )
    628                                                         $output .= '<a href="' . add_query_arg('page', $i, get_permalink()) . '">';
     641                                                        $output .= '<a class="pag_nav_next" href="' . add_query_arg('page', $i, get_permalink()) . '">' . $link_before . $nextpagelink . $link_after . '</a>';
    629642                                                elseif ( 'page' == get_option('show_on_front') && get_option('page_on_front') == $post->ID )
    630                                                         $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
     643                                                        $output .= '<a class="pag_nav_next"  href="' . trailingslashit(get_permalink()) . user_trailingslashit('page/' . $i, 'single_paged'). '">';
    631644                                                else
    632                                                         $output .= '<a href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">';
     645                                                        $output .= '<a class="pag_nav_next" href="' . trailingslashit(get_permalink()) . user_trailingslashit($i, 'single_paged') . '">' . $link_before. $nextpagelink . $link_after . '</a>';
    633646                                        }
    634                                         $output .= $link_before. $nextpagelink . $link_after . '</a>';
    635647                                }
    636648                                $output .= $after;
    637649                        }