- This topic has 19 replies, 6 voices, and was last updated 4 years, 1 month ago by Tom.
-
AuthorPosts
-
August 29, 2018 at 11:23 am #663569Scrat
Hi, I’ve made a custom template in order to target certain pages with the elements module. However, I can’t seem to get the custom template to appear in the display rules. Steps to reproduce:
– Copy page.php from parent theme into child theme directory, renamed file to page-fullwidth.php, and added /* Template Name: Full Width Page */. So far so good – I have pages that are now Full Width Pages.
– Create a new header element Page Header Full Width.
– In Display Rules for the new header element, Location > Templates > [expected: Full Width Page; but it’s not here].Note: the problem I’m trying to solve is not to get custom templates to appear in the display rules per se; rather, I’d just like to have a way to target a group of pages, and templates seem to be a sensible way to do it. I’m open to other ideas.
Thank you!
August 29, 2018 at 2:41 pm #663694LeoStaffCustomer SupportHi there,
So just to make sure, that group of pages you are trying to target have no existing relationships at all?
August 29, 2018 at 3:07 pm #663704Scrat> So just to make sure, that group of pages you are trying to target have no existing relationships at all?
They all use the same template.
(They are also all subpages of a parent page, but there are other pages planned that will need to use the same header element that won’t. I don’t see a way to target subpages in the elements module either, so that point is probably moot.)
The idea is to set a header rule for pages that use the full-width layout. The client wants multiple pages that share the same header layout, each of which uses a different background image, heading, and tagline. The elements module makes it super easy to do so – I just can’t see the custom template I created in the list of display rules.
August 29, 2018 at 3:16 pm #663707ScratI should also clarify – I’m trying to set a rule for pages that use a custom template that I called “Page Header Full Width”, not the Generatepress native full-width page layout option. The problem is that I can’t target custom templates in the element display rules. So if I made a template called Steve, for instance, I would expect to see Steve in Elements > [rule name] > Display Rules > Location > Templates > [here]. Hope that helps.
August 29, 2018 at 7:02 pm #663800TomLead DeveloperLead DeveloperHi there,
Display rules won’t display page templates unfortunately – they only display post types and taxonomies.
However, we can use a filter if we have the ID of the element:
add_filter( 'generate_header_element_display', function( $display, $element_id ) { if ( is_page_template( 'your-template.php' ) && 20 === $element_id ) { return true; } return $display; }, 10, 2 );
The above assumes the ID of the element is:
20
September 13, 2018 at 2:33 am #676080ic7Hi Tom,
I also would like to assign a layout element to all pages that use a certain page template via display rules. But unfortunately I couldn’t get the above mentioned filter to work in my local test installation:
I edited the template name and the ID of the layout element and copied the code to my child theme’s functions.php. Did I miss something?
Do you plan to implement display rules for page templates in the future?
That would be so awesome (… and useful :))!Thank you so much for your great work!
Best regards,
SebastianSeptember 13, 2018 at 8:48 am #676484TomLead DeveloperLead DeveloperI’ll definitely look into it, but I’m not sure how possible it will be.
What’s the name of your template file?
September 14, 2018 at 2:30 am #676967ic7The name of my template file is ‘page-stack.php’, the element ID is 442.
// GPP - LAYOUT ELEMENT FOR 'STACK' PAGE TEMPLATE add_filter( 'generate_header_element_display', function( $display, $element_id ) { if ( is_page_template( 'page-stack.php' ) && 442 === $element_id ) { return true; } return $display; }, 10, 2 );
September 14, 2018 at 9:13 am #677309TomLead DeveloperLead DeveloperHmm, do you see a message below the header if you do this?:
add_action( 'generate_after_header', function() { if ( is_page_template( 'page-stack.php' ) ) { echo 'test'; } } );
September 14, 2018 at 9:23 am #677324ic7Yes I do. ‘test’ is sitting between the header and the content-wrapper.
September 14, 2018 at 9:33 am #677337TomLead DeveloperLead DeveloperOk, so your conditions look fine.
Just to confirm, another header element isn’t already assigned to that page?
September 14, 2018 at 9:45 am #677351ic7No. I created one layout element (no sidebars, no title, full-width) and assigned it to my front-page via display rules. My front-page uses the above mentioned page-stack.php template. Now I’m looking for a way to apply the layout element to all pages that use the page-stack.php template. The code above is in place (functions.php). But if I assign the page-template to a new page, this page still has sidebar, title and boxed content.
September 14, 2018 at 8:06 pm #677587TomLead DeveloperLead DeveloperRight now only one Layout can be active on a specific page. We’re changing this in GPP 1.8.
So if a Layout element is already active due to it being the front page, the other Layout elements won’t apply even if it’s set to the page template.
September 15, 2018 at 1:00 am #677639ic7Okay. So for the moment, the only way to apply the layout element to all pages using my custom page template is to set the display rules to ALL pages and than exclude the pages that don’t use the custom page template?
That works for me. The ability to set the display rules by page template would be awesome though.
Already looking forward to 1.8 ๐Thanks again for your work and great support!
September 15, 2018 at 9:14 am #677987TomLead DeveloperLead DeveloperThat’s correct ๐
No problem!
-
AuthorPosts
- You must be logged in to reply to this topic.