Site logo

Archived topic

Wp-PageNavi for Multipart-pages with GP?

4 replies · Started by Mike on May 23, 2020

Viewing posts 1–5 of 5

Hi,

Using WP-PageNavi - working fine for category pages, blog etc.
Basic code added via snippets.

I now want to implement it to represent page navigation within multi-part pages (pages created by inserting a new page marker in Gutenberg).

WP-PageNavi site says: you can also use WP PageNavi for multipart or paginated pages (pages using the “wp_link_pages” tag) by simply using this code:

<?php wp_pagenavi( array( 'type' => 'multipart' ) ); ?>

I was hoping to find a hook that would allow me to attach the code somehow.

Any ideas?

Thanks
Mike

Hi,

OK - so I think I have solved this, but would appreciate if you'd let me know if I've done it correctly. It certainly now works for both single posts and pages that have been split into multiple pages.

I copied both content-single.php and content-page.php into my child theme.

I edited both and made the following change - first commenting out the wp_link_pages part and then inserting the wp_pagenavi line to replace what was commented out.


/*
			wp_link_pages( array(
				'before' => '<div class="page-links">' . __( 'Pages:', 'generatepress' ),
				'after'  => '</div>',
			) );
*/

wp_pagenavi( array( 'type' => 'multipart' ) );

I did this in both files, it's the same change.

Thanks for taking time to look at my change - I thought it would be worth having this in the help forum anyway in case someone else needs it - it might save you back the time I wasted :-)

Loving Generatepress. It rocks. Stay safe in the weird times.

Mike

Hey Mike,

Nothing wrong with that method at all.

If you want to try without overwriting template files, this *might* work:

add_filter( 'wp_link_pages', function() {
    wp_pagenavi( array( 'type' => 'multipart' ) );
} );

Not 100% sure, but it's worth a shot :)

Hi Tom,

That didn't work initially, it gave a syntax error in Snippets and even after correcting that (missing ; on line 2) it still didn't work. With no understanding of what I was doing I then removed
'echo' => false
and it all came to life. I had already renamed the template files in my child theme ".old" and can now remove them.

So the final code was:

add_filter( 'wp_link_pages', function() {
    wp_pagenavi( array( 'type' => 'multipart' ) );
} );

Thanks for the advice to use Snippets - for someone just learning PHP, this has been amazingly helpful!

thanks,
Mike

Sorry about the error! Glad it's working now :)

This archived topic is closed to new replies.