-1

I have used <!--nextpage--> tag to paginate longer individual posts, These longer single posts have structure as Title, Content, A, B, C, By using above said tag, I want to paginate A, B, C content only and show title, content on all the paginated pages. How can I do this?

2

It's possible to modify the content pagination with the content_pagination filter.

Here's a way to always display the content of the first page:

/**
 * Content Pagination: Always display the content of the first page
 */
add_filter( 'content_pagination', function( $pages )
{
    // Nothing to do if there's no pagination
    if( count( $pages ) <= 1 )
        return $pages;

    // Get the first page and remove it from the pages array
    $firstpage = array_shift( $pages );

    // Prepend the first page to all other pages
    foreach( $pages as &$page )
        $page = $firstpage . $page;

    // Add the first page again
    array_unshift( $pages, $firstpage );

    return $pages;
} );

Example:

Let's assume the content pagination is defined as:

aaa
<!--nextpage-->
bbb
<!--nextpage-->
ccc

Then the first page is:

aaa

The second one becomes:

aaa
bbb

and the third one displays as:

aaa
ccc

Update:

To have the first page as:

aaa
bbb

the second one as:

aaa
ccc

etc, then we only need to comment out this line:

// Add the first page again
array_unshift( $pages, $firstpage );
  • But i have aaa,bbb,ccc,ddd and i want to show aaa, bbb on first page and aaa ccc, aaa ddd on next pages. – PARVINDER Aug 6 '16 at 2:03
  • You only need to remove a single line of code from the snippet, can you see which one? @PARVINDER – birgire Aug 6 '16 at 8:34
  • Can u explain @birgire – PARVINDER Aug 6 '16 at 12:59
  • Please check out the updated answer @PARVINDER – birgire Aug 6 '16 at 15:35
  • Any progress on the problem? @PARVINDER – birgire Aug 25 '16 at 15:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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