Archived topic
How to make GP "Elements Block-Content Template" work on Custom Page Template
5 replies · Started by Jose Salgado on October 2, 2021
Hi,
I am trying to move from Elementor to Gutenberg and Generate Blocks.
So far, I am starting to get use to "Elements" of GP Pro and the concept of Theme Builder.
But recently I found something I want to do but Im not sure if its posible, so let me explain:
I created a"WordPress Theme Custom Page Template" following this guide: https://wpshout.com/wordpress-custom-page-template/
Here is an image to ilustrate: https://drive.google.com/file/d/1_Ho6DjCgOhI5KJTySqU6PjH8uEHNLubQ/view?usp=sharing
So, this "Custom Page Templates" appear into Gutenberg Editor Panel.
Then I Go to "GP Elements" - Create a new Block Template - Then Design the Template using "GP Dynamic Block Elements" - then, Apply Display Rules
So here is my question, it is posible to make that the "WordPress Theme Custom Page Template" appear into the display rules?. (Something similar like using CPT (Custom Post Types) - that you can apply different design depending de CPT, but for "WordPress Theme Custom Page Template")
Here its more images of what I am talking about:
https://drive.google.com/file/d/1wFhzXy9qAtVAx6DXeBfGeHd3nVq9BCmu/view?usp=sharing
https://drive.google.com/file/d/1oWdA9HfH3ACLubuKHpDskzkTzzmCuh0a/view?usp=sharing
I hope I have explained myself well.
Hi there,
are the Custom Page Templates adding anything 'special' to the page ? Or are you simply wanting to use it to select a different Content Template ( or other Elements ) ?
Hi David,
I just simple copy de "page.php" in generate press theme folder, then paste it on Generatepress Child Theme Folder, then rename it.
So it has the same. Let me put the code:
::::::::::::::::::::::::
<?php
/*
Template Name: Imagen Arriba
Template Post Type: post, page
*/
/**
* The template for displaying all pages.
*
* This is the template that displays all pages by default.
* Please note that this is the WordPress construct of pages
* and that other 'pages' on your WordPress site will use a
* different template.
*
* @package GeneratePress
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
get_header(); ?>
<main id="main" <?php generate_do_element_classes( 'main' ); ?>>
<?php
/**
* generate_before_main_content hook.
*
* @since 0.1
*/
do_action( 'generate_before_main_content' );
if ( generate_has_default_loop() ) {
while ( have_posts() ) :
the_post();
generate_do_template_part( 'page' );
endwhile;
}
/**
* generate_after_main_content hook.
*
* @since 0.1
*/
do_action( 'generate_after_main_content' );
?>
</main>
<?php
/**
* generate_after_primary_content_area hook.
*
* @since 2.0
*/
do_action( 'generate_after_primary_content_area' );
generate_construct_sidebars();
get_footer();
::::::::::::
If there its a better code that you recommend, i could change it.
There isn't a built i Display Rule for selecting Custom Page Templates.
We could write some code to make an element appear on a specific page template, but you would have to add more code for each and every template you add.
As your Custom Templates have no special requirements, i would personally NOT bother creating them.
Instead you could use the PHP Snippet i provide here:
https://generatepress.com/forums/topic/reducing-the-number-of-element-headers/#post-1942770
With that it creates a Custom Taxonomy called Element Controls in pages and posts, then you can simply create a new Taxonomy Term eg. Page Template One
Then create an Element and set its Display Rules to Element Control > Page Template One.
It will do the exact same thing as generating new Page Templates without the need for the additional page templates or custom code. And you can also check the Element Control taxonomy ( like Categories and Tags ) and see every Page that has been assigned to that control term.
I Loved your solution, that was a great alternative. Now works as expected.
Thanks David.
Awesome - so glad to hear that!!!