Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Does someone have a solution to display only the nextpagelink with wp_link_pages in single posts? I've tried different solutions, but none of it worked.

As I reach the last page - wp_link_pages remove nextpagelink and show previouspagelink. But I need only nextpagelink at all pages except last one.

Or maybe a solution to add class for nextpagelink?

Found solution:

<?php global $multipage, $numpages, $page; 
if( $multipage && $page == $numpages )
 {
   //Do nothing
 } else { 
 wp_link_pages('before=&after=&next_or_number=next&previouspagelink=&nextpagelin‌​k=More'); 
} ?>
share|improve this question
2  
Add your solution as a real answer, and mark it as The Answer. Do not put the answer into your question. –  toscho Jan 27 '13 at 13:27

1 Answer 1

You'll have to prepare your own custom function instead of wp_link_pages to use in single.php file of your template.

Here's the custom function my_wp_link_pages proposal (contains original wp_link_pages code with commented out lines):

function my_wp_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;
            for ( $i = 1; $i < ($numpages+1); $i = $i + 1 ) {
                $j = str_replace('%',$i,$pagelink);
                $output .= ' ';
                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 .= $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 .= $after;
            }
        }
    }

    if ( $echo )
        echo $output;

    return $output;
}
share|improve this answer
    
Thanks i will try. But i just found solution what work for me: <?php global $multipage, $numpages, $page; if( $multipage && $page == $numpages ) { } else { wp_link_pages('before=&after=&next_or_number=next&previouspagelink=&nextpagelin‌​k=More'); } ?> it just show only Next_link on all pages except last one. while not fully tested, but at first glance it works fine –  Lee Miller Jan 27 '13 at 12:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.