- This topic has 8 replies, 2 voices, and was last updated 3 months, 3 weeks ago by
David.
-
AuthorPosts
-
December 28, 2019 at 2:56 am #1115795
gatepress
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 #1116184Tom
Lead 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 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 28, 2019 at 9:35 am #1116214gatepress
Hi 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 #1116243gatepress
Sorry, 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 #1116428Tom
Lead DeveloperLead DeveloperThat’s right – did you also update the page parent ID?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentDecember 29, 2019 at 3:49 am #1116600gatepress
yes 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 #1116863Tom
Lead DeveloperLead DeveloperAh yes – filters need to be added in your functions.php file or in Code Snippets 🙂
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentSeptember 28, 2020 at 6:05 am #1462109Long
it is not working with CPT children, can you advise how to make it work?
Thanks a lot
September 28, 2020 at 6:54 am #1462169David
StaffCustomer 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/
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.