[Resolved] Element display rules makes bad flow for creating pages.

Home Forums Support [Resolved] Element display rules makes bad flow for creating pages.

Home Forums Support Element display rules makes bad flow for creating pages.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #703331
    Lars Steen

    Hello GP.

    It seems that i can’t change header pr. page in a easy way.

    Why is it that it’s not possible to choose what header to display on each page, and then make an override of the elements header display rules?

    It’s seems like it gives a lot of confusion, if you have 3 types of headers for pages for example.

    What do you recommend I do about it?
    And i’m not sure how to explain this simple to end admin user.

    What approach do you recommend here?

    Best regards. Lars.

    GP Premium 1.7.2
    #703595
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Are you wanting a select dropdown while creating pages to select a Header, kind of like the old Page Header module?

    This is something we wanted to move away from in Elements. It adds an additional layer of complexity and can be confusing when Display Rules aren’t working (because a metabox is set instead).

    The direction of WordPress (Gutenberg, no metaboxes) was also a factor in our decision.

    Instead, it’s actually really easy to choose pages directly within the Header Element. This way all of your conditions are within one area.

    #703604
    Lars Steen

    Hello Tom

    Thanks for the fast response.

    “Are you wanting a select dropdown while creating pages to select a Header, kind of like the old Page Header module?”
    Yes. I think this is needed. I will build this myself then.

    “The direction of WordPress (Gutenberg, no metaboxes) was also a factor in our decision”
    I think it’s too early to remove it totally still.

    Maybe I Just don’t get it. But would the meta boxes not just live inside a Gutenberg “block” if needed? If so, isn’t this just another way to override like the old page header module?

    Feel free to correct me if i’m wrong.

    Best regards. Lars.

    #703609
    Tom
    Lead Developer
    Lead Developer

    The way Page Headers worked per page was something I didn’t really like before. However, I’m always open to feedback when it comes to this kind of stuff.

    Let me know if you need any help building a solution – the code telling the Header to apply shouldn’t be too hard with the generate_header_element_display filter.

    #703840
    Lars Steen

    Hello Tom.

    Thanks for wanting to help.

    I choose to do it via AFC.

    Here is my code, to get somebody started if they want the same.

    In ACF create and assign the post_object field to the page, make it return an ID

    Code goes in fx. functions.php

    // filter for a specific field based on it's name the ACF field is of the type post_object
    add_filter('acf/fields/post_object/query/name=choose_header', 'm_query_headers_post_object_query', 10,3);
    function m_query_headers_post_object_query( $args, $field, $post_id ) {
    
        // Only show GPP headers
        $args['meta_query'] = array(
            array(
                'key' => '_generate_element_type',
                'value' => 'header',
                'compare' => 'EXISTS'
            ),
        );
    
        // return
        return $args;
    }
    
    add_filter( 'generate_header_element_display', 'm_control_show_header',10, 2 );
    function m_control_show_header ($display, $element_id) {
        global $post;
    
        // Try to get the header id
        $id_of_header_to_display = get_field('choose_header',$post->ID);
    
        // Check if it's assigned
        if (is_int($id_of_header_to_display)) {
            if ($element_id == $id_of_header_to_display) {
                return true;
            }
        } else {
            // Or do normal GPP
            return $display;
        }
    }
    

    It’s working for my needs for now, NB. Did not test fully yet.

    Best regards. Lars.

    #704336
    Tom
    Lead Developer
    Lead Developer

    Great work – exactly how I would have done it 🙂

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