🎉 Happy 4th of July! Get 15% off GP Premium with the discount code: 4THOFJULY2020

[Resolved] Display Rule for child pages

Home Forums Support Display Rule for child pages

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #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!

    #1116184
    Tom
    Lead Developer
    Lead Developer

    Hi 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 🙂

    #1116214
    gatepress

    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!

    #1116243
    gatepress

    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.

    #1116428
    Tom
    Lead Developer
    Lead Developer

    That’s right – did you also update the page parent ID?

    #1116600
    gatepress

    yes both.

    I used the plugin code snippets now and it works. Maybe it was a misunderstanding using two hooks for that?

    #1116863
    Tom
    Lead Developer
    Lead Developer

    Ah yes – filters need to be added in your functions.php file or in Code Snippets 🙂

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.