最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论