- This topic has 4 replies, 2 voices, and was last updated 3 years, 11 months ago by Tom.
-
AuthorPosts
-
May 23, 2020 at 7:39 pm #1298666Mike
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
MikeMay 23, 2020 at 8:37 pm #1298693MikeHi,
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
May 24, 2020 at 11:04 am #1299554TomLead DeveloperLead DeveloperHey 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 🙂
May 24, 2020 at 6:14 pm #1299863MikeHi 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,
MikeMay 25, 2020 at 9:22 am #1300821TomLead DeveloperLead DeveloperSorry about the error! Glad it’s working now 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.