最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp link pages - Post Pagination Customization (wp_link_pages) Editing Navigation

matteradmin8PV0评论

I want to create a post pagination where there is only ONE 'nextpagelink' button per page.

However, I want the text inside the the first 'nextpagelink' to say "WELCOME".

And I want the text inside every 'nextpagelink' after that to say "NEXT PAGE".

Quick Schematic

I figured out the "NEXT PAGE" part:

The following is inside single.php

wp_link_pages( array(
'before' => '<div id="slideshow">',
'after' => '</div>',
'next_or_number' => 'next', 
'previouspagelink' => '<span id="previous" style="display:none;"> PREVIOUS SLIDE </span>',  
'nextpagelink' => '<span id="next"> NEXT PAGE </span>'
)); ?>

The problem is that it makes ALL 'nextpagelink' "NEXT PAGE"

I am trying the following but its not really working:

The following is inside post-template.php

            if ( $next = 1 ) {
            $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink_first'] . $r['link_after'] . '</a>';

Where "nextpagelink_first" = 'WELCOME'

All that does is display 'WELCOME' next to 'NEXT PAGE', and 'WELCOME' always points to first slide, not good.

Please help!

I want to create a post pagination where there is only ONE 'nextpagelink' button per page.

However, I want the text inside the the first 'nextpagelink' to say "WELCOME".

And I want the text inside every 'nextpagelink' after that to say "NEXT PAGE".

Quick Schematic

I figured out the "NEXT PAGE" part:

The following is inside single.php

wp_link_pages( array(
'before' => '<div id="slideshow">',
'after' => '</div>',
'next_or_number' => 'next', 
'previouspagelink' => '<span id="previous" style="display:none;"> PREVIOUS SLIDE </span>',  
'nextpagelink' => '<span id="next"> NEXT PAGE </span>'
)); ?>

The problem is that it makes ALL 'nextpagelink' "NEXT PAGE"

I am trying the following but its not really working:

The following is inside post-template.php

            if ( $next = 1 ) {
            $link = _wp_link_page( $next ) . $r['link_before'] . $r['nextpagelink_first'] . $r['link_after'] . '</a>';

Where "nextpagelink_first" = 'WELCOME'

All that does is display 'WELCOME' next to 'NEXT PAGE', and 'WELCOME' always points to first slide, not good.

Please help!

Share Improve this question asked Apr 1, 2019 at 19:03 DiscoverDiscover 331 gold badge1 silver badge6 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

It makes all pages show "NEXT PAGE", because you don't tell it that it should be any different.

What you need is to set that link conditionally based on which page is currently displayed:

wp_link_pages( array(
    'before' => '<div id="slideshow">',
    'after' => '</div>',
    'next_or_number' => 'next', 
    'previouspagelink' => '<span id="previous" style="display:none;"> PREVIOUS SLIDE </span>',  
    'nextpagelink' => ( get_query_var('page') < 2 ) ? '<span id="next"> WELCOME </span>' : '<span id="next"> NEXT PAGE </span>'
) );

This uses a conditional statement:

( get_query_var('page') < 2 ) ? '<span id="next"> WELCOME </span>' : '<span id="next"> NEXT PAGE </span>'

which checks the current page (you can get it by checking page query var) and returning one of the strings based on the condition (here we check if it's the first page or any other).

You can read more on page query var here: What is the difference between $paged and $page?

Post a comment

comment list (0)

  1. No comments so far