admin管理员组

文章数量:1025814

I want 'nextpagelink' shortcode [nextpage_shortcode] that I can place inside content.

I've seen threads where they say that you can't place anything related to the wp_link_pages inside content due to the way the content is rendered by Wordpress.

As you can see the text of 'nextpagelink' changes depending on the slide #.

I want the shortcode to reflect that.

Here is the schematic of what I am looking to do:

Both 'BEGIN' buttons link to the 2nd slide.

This is what I am currently working on:

function nextpage_shortcode( $atts ) { wp_link_pages( array(

'before' => '<div id="slideshow">',
'after' => '</div>',
'next_or_number' => 'next', 
'nextpagelink' => ( get_query_var('page') < 2 ) ? '<span id="next"> BEGIN </span>' : '<span id="next"> NEXT </span>' ) );

return ['nextpagelink'];
} add_shortcode( 'nextpage_short', 'nextpage_shortcode' );

Its works somewhat.

Its posts the 'nextpagelink' button above content, but not inside the content.

Not sure how to proceed.

Please help!

I want 'nextpagelink' shortcode [nextpage_shortcode] that I can place inside content.

I've seen threads where they say that you can't place anything related to the wp_link_pages inside content due to the way the content is rendered by Wordpress.

As you can see the text of 'nextpagelink' changes depending on the slide #.

I want the shortcode to reflect that.

Here is the schematic of what I am looking to do:

Both 'BEGIN' buttons link to the 2nd slide.

This is what I am currently working on:

function nextpage_shortcode( $atts ) { wp_link_pages( array(

'before' => '<div id="slideshow">',
'after' => '</div>',
'next_or_number' => 'next', 
'nextpagelink' => ( get_query_var('page') < 2 ) ? '<span id="next"> BEGIN </span>' : '<span id="next"> NEXT </span>' ) );

return ['nextpagelink'];
} add_shortcode( 'nextpage_short', 'nextpage_shortcode' );

Its works somewhat.

Its posts the 'nextpagelink' button above content, but not inside the content.

Not sure how to proceed.

Please help!

Share Improve this question edited Apr 1, 2019 at 23:20 Discover asked Apr 1, 2019 at 21:23 DiscoverDiscover 331 gold badge1 silver badge6 bronze badges 2
  • This has been answered at wordpress.stackexchange/questions/183978/… – Donna McMaster Commented Apr 1, 2019 at 22:30
  • Thanks for your response! Correct me I am wrong but the link you've provided simply turns <!--nextpage--> into a shortcode. I don't want [nextpage_shortcode] to actually split content. I want it to refer to the <!--nextpage--> below it. – Discover Commented Apr 1, 2019 at 22:50
Add a comment  | 

1 Answer 1

Reset to default 0

wp_link_pages() by default echoes the links (or the output), unless you set the echo parameter to 0 (or false). Secondly, your code is returning an array with nextpagelink as the only item/value.

But anyway, if you just want the link to the next page, the wp_link_pages() wouldn't be the one you should be using since it outputs all the page links (start, next, previous, etc.).

Instead, you can try this, which works well for me:

function nextpage_shortcode( $atts ) {
    global $page, $numpages, $multipage;
    if ( $multipage ) {
        $i = max( 1, $page );
        if ( $i < 2 ) {
            $text = '<span id="next"> BEGIN </span>';
        } elseif ( $i < $numpages ) {
            $text = '<span id="next"> NEXT </span>';
        }
        if ( ! empty( $text ) ) {
            $link = _wp_link_page( $i + 1 );
            return $link . $text . '</a>';
        }
    }
    return '';
}
add_shortcode( 'nextpage_short', 'nextpage_shortcode' );

However, you should know that I'm using _wp_link_page() which is a private function. So you might want to copy the source, rename the function (e.g. to my_link_page), and use my_link_page() in the above code.

I hope that helps, and remember that the <!--more--> tag (i.e. content teaser) is not being taken into account since you're specifically dealing with the <!--nextpage--> tag only.

I want 'nextpagelink' shortcode [nextpage_shortcode] that I can place inside content.

I've seen threads where they say that you can't place anything related to the wp_link_pages inside content due to the way the content is rendered by Wordpress.

As you can see the text of 'nextpagelink' changes depending on the slide #.

I want the shortcode to reflect that.

Here is the schematic of what I am looking to do:

Both 'BEGIN' buttons link to the 2nd slide.

This is what I am currently working on:

function nextpage_shortcode( $atts ) { wp_link_pages( array(

'before' => '<div id="slideshow">',
'after' => '</div>',
'next_or_number' => 'next', 
'nextpagelink' => ( get_query_var('page') < 2 ) ? '<span id="next"> BEGIN </span>' : '<span id="next"> NEXT </span>' ) );

return ['nextpagelink'];
} add_shortcode( 'nextpage_short', 'nextpage_shortcode' );

Its works somewhat.

Its posts the 'nextpagelink' button above content, but not inside the content.

Not sure how to proceed.

Please help!

I want 'nextpagelink' shortcode [nextpage_shortcode] that I can place inside content.

I've seen threads where they say that you can't place anything related to the wp_link_pages inside content due to the way the content is rendered by Wordpress.

As you can see the text of 'nextpagelink' changes depending on the slide #.

I want the shortcode to reflect that.

Here is the schematic of what I am looking to do:

Both 'BEGIN' buttons link to the 2nd slide.

This is what I am currently working on:

function nextpage_shortcode( $atts ) { wp_link_pages( array(

'before' => '<div id="slideshow">',
'after' => '</div>',
'next_or_number' => 'next', 
'nextpagelink' => ( get_query_var('page') < 2 ) ? '<span id="next"> BEGIN </span>' : '<span id="next"> NEXT </span>' ) );

return ['nextpagelink'];
} add_shortcode( 'nextpage_short', 'nextpage_shortcode' );

Its works somewhat.

Its posts the 'nextpagelink' button above content, but not inside the content.

Not sure how to proceed.

Please help!

Share Improve this question edited Apr 1, 2019 at 23:20 Discover asked Apr 1, 2019 at 21:23 DiscoverDiscover 331 gold badge1 silver badge6 bronze badges 2
  • This has been answered at wordpress.stackexchange/questions/183978/… – Donna McMaster Commented Apr 1, 2019 at 22:30
  • Thanks for your response! Correct me I am wrong but the link you've provided simply turns <!--nextpage--> into a shortcode. I don't want [nextpage_shortcode] to actually split content. I want it to refer to the <!--nextpage--> below it. – Discover Commented Apr 1, 2019 at 22:50
Add a comment  | 

1 Answer 1

Reset to default 0

wp_link_pages() by default echoes the links (or the output), unless you set the echo parameter to 0 (or false). Secondly, your code is returning an array with nextpagelink as the only item/value.

But anyway, if you just want the link to the next page, the wp_link_pages() wouldn't be the one you should be using since it outputs all the page links (start, next, previous, etc.).

Instead, you can try this, which works well for me:

function nextpage_shortcode( $atts ) {
    global $page, $numpages, $multipage;
    if ( $multipage ) {
        $i = max( 1, $page );
        if ( $i < 2 ) {
            $text = '<span id="next"> BEGIN </span>';
        } elseif ( $i < $numpages ) {
            $text = '<span id="next"> NEXT </span>';
        }
        if ( ! empty( $text ) ) {
            $link = _wp_link_page( $i + 1 );
            return $link . $text . '</a>';
        }
    }
    return '';
}
add_shortcode( 'nextpage_short', 'nextpage_shortcode' );

However, you should know that I'm using _wp_link_page() which is a private function. So you might want to copy the source, rename the function (e.g. to my_link_page), and use my_link_page() in the above code.

I hope that helps, and remember that the <!--more--> tag (i.e. content teaser) is not being taken into account since you're specifically dealing with the <!--nextpage--> tag only.

本文标签: paginationwplinkpages shortcode for 39nextpagelink39