- This topic has 9 replies, 3 voices, and was last updated 4 years, 7 months ago by
David.
-
AuthorPosts
-
September 2, 2021 at 2:45 pm #1917051
George
I have set a pagination template block element to only appear below children of a particular page:
add_filter( 'generate_block_element_display', function( $display, $element_id ) { global $post; if ( 11024234 === $element_id && ( is_page() && $post->post_parent == '11017715' ) ) { $display = true; } return $display; }, 10, 2 );Is it possible to restrict the pagination only to those child pages?
September 2, 2021 at 9:04 pm #1917194Elvin
StaffCustomer SupportHi George,
Can you try this?
add_filter( 'generate_hook_element_display', function( $display, $element_id ) { $args = array( 'child_of' => 11017715, ); $pages = get_pages($args); $pageID = array(); foreach($pages as $page){ $pageID[] = $page->ID; } if ( 11024234 === $element_id && is_page($pageID) ) { $display = true; } return $display; }, 20, 2 );September 3, 2021 at 5:50 am #1917634George
Thanks, Elvin, just tested it, it still includes some other random pages.
September 3, 2021 at 6:59 am #1917671David
StaffCustomer SupportHi George,
First off – does it work on the child pages it is meant to ?
September 3, 2021 at 7:35 am #1917703George
Yes, it does, just like the code, I showed in my initial post. It’s just that navigating with previous, next will eventually show a page that is not a child of the stated parent.
September 3, 2021 at 8:28 am #1917936David
StaffCustomer SupportHmmm… i am not sure theres a solution for that, to best of my knowledge GP is using the
get_next_post_link( and get_prev ) functions for those links:https://developer.wordpress.org/reference/functions/get_next_post_link/
Which doesn’t have any options in regards to page hierarchy.
I think you would need to create you won paging nav. Heres an example function that sounds like its doing the same thing:
September 3, 2021 at 9:44 am #1918010George
I managed to make it work with the code you provided, David. The only thing is that when I use
gp130428_paginate_parent_children( 123 )the pagination also includes the parent page. Is there a way to exclude the parent?September 4, 2021 at 3:38 am #1918501David
StaffCustomer SupportLine 37 looks to be where it outputs the Page parent title. Try replacing that line that with just a HTML Comment eg.
<!-- does nothing -->See what happens 🙂
September 4, 2021 at 5:07 am #1918559George
Yeah, I tried all that stuff, it didn’t work. Never mind, I will play some more with it and see what happens.
Thanks, David 🙂
September 5, 2021 at 3:49 am #1919298David
StaffCustomer SupportNo problems – hope you find a solution!
-
AuthorPosts
- You must be logged in to reply to this topic.