- This topic has 9 replies, 3 voices, and was last updated 1 year, 7 months ago by Gabriel.
-
AuthorPosts
-
December 28, 2019 at 2:56 am #1115795Regina
Hi there,
I created a hook with an arrow linked to the parent page, which I want to display on all child pages of one parent page, but not on the parent page itself. I miss the exact display rule like “all child pages” in combination with “parent page”. Is it possible to create my own display rule?
I found the following – do I have to create two hooks and one with something like this?:
***
Another useful example is to set the hook to display on the parent page and all the child pages automatically:add_filter( 'generate_hook_element_display', function( $display, $element_id ) { global $post; if ( 1180 === $element_id && ( is_page() && $post->post_parent == '415' ) ) { $display = true; } return $display; }, 10, 2 );
You need to replace 1180 with the ID of your Element, and 415 with the ID of the parent page.
***Thank you so much in advance!
December 28, 2019 at 8:51 am #1116184TomLead DeveloperLead DeveloperHi there,
That one filter should do exactly what you’re looking for.
All you need to do is:
1. Create the Hook, and note the Hook ID (it’s in the URL when you save your hook).
2. Replace 1180 in the filter with the ID.
3. Replace 415 in the filter with the ID of the parent page you’re targeting.That should be it.
We’re planning on adding a Child Page option in the Display Rules soon 🙂
December 28, 2019 at 9:35 am #1116214ReginaHi Tom,
and how do I find out the ID of my Element? Do I allocate it in the code of my element myself?
I choosed custom hook and also checked PHP in the hook withe the code. Is a location rule necessary? (Actually I have it in the Element hook.)
Do not plan too long to add this Child Page option in the Display Rules 😉
Thanks again!
December 28, 2019 at 10:37 am #1116243ReginaSorry, you already wrote, that the ID is in the URL.
it´s …/post.php?post=1513&action=edit
I think the ID must be 1513 (?)It still doesn´t work.
December 28, 2019 at 5:24 pm #1116428TomLead DeveloperLead DeveloperThat’s right – did you also update the page parent ID?
December 29, 2019 at 3:49 am #1116600Reginayes both.
I used the plugin code snippets now and it works. Maybe it was a misunderstanding using two hooks for that?
December 29, 2019 at 9:16 am #1116863TomLead DeveloperLead DeveloperAh yes – filters need to be added in your functions.php file or in Code Snippets 🙂
September 28, 2020 at 6:05 am #1462109jasondit is not working with CPT children, can you advise how to make it work?
Thanks a lot
September 28, 2020 at 6:54 am #1462169DavidStaffCustomer SupportHi there,
this line:
if ( 1180 === $element_id && ( is_page() && $post->post_parent == '415' ) ) {
one of the conditions
is_page()
needs to be changed foris_singluar('your-cpt')
:https://developer.wordpress.org/reference/functions/is_singular/
September 22, 2022 at 5:34 am #2350503Gabriel+1 for pages rules based on parent page
-
AuthorPosts
- You must be logged in to reply to this topic.