- This topic has 7 replies, 4 voices, and was last updated 4 years, 11 months ago by
David.
-
AuthorPosts
-
June 17, 2021 at 1:33 pm #1825856
Jim
I can’t find any documentation on the process of editing a custom page template. The methods outlined in the web at large don’t seem to work for GP. I’ve read many forum topics but none seem to help.
All I’m trying to do is add some standard html (headings, images) that appears the same in a common kind of page. I copied page.php into the child theme and renamed it disease-template.php with a heading to match. It shows up in the page editor just fine.
Problem is where to add the html. I tried in the template after
if ( generate_has_default_loop() )section, closing and reopening the php tags before and after. It didn’t show in the editor. It did show when viewing the page, but no style.Then I tried changing the generate_do_template_part call to
generate_do_template_part( 'content', 'disease' );copied content-page.php and renamed it content-disease.php, and pasted in the html after<div class="entry-content"<?php echo $itemprop; // phpcs:ignore -- No escaping needed. ?>> <?php the_content(); ?>But it doesn’t show up at all. What’s the secret? Thanks!
June 17, 2021 at 2:55 pm #1825919Ying
StaffCustomer SupportHi Jim,
It doesn’t have to be this complicated, you can use a hook element if you want to add HTML to certain kinds of pages.
https://docs.generatepress.com/article/hooks-element-overview/And here’s the visual guide of hooks:
https://docs.generatepress.com/article/hooks-visual-guide/If you’d like to use Gutenburg, you can use block element instead of hook element:
https://docs.generatepress.com/article/block-element-overview/Hope it’s helpful 🙂
June 17, 2021 at 3:11 pm #1825929Jim
Thanks. The hooks element article is not clear to me, it doesn’t mention where you put the content. Anyway, I don’t think hooks will work.
I just want a template to start with, then I start filling in unique content in and between the html elements from the template for an individual page that uses the template. I suspect the hooks will simply insert the html as the page is generated, which isn’t what I’m after.
Or will templates not do what I want either?
June 17, 2021 at 9:02 pm #1826060Elvin
StaffCustomer SupportHi Jim,
Can you specify with part of the post type and which part page do you want the HTMLs to be placed?
If it’s within what
the_content()outputs, you may have to do astr_replace()the content to add it in.Or completely change how you create the content by adding a portable hook on every entry so you can use it to hook things in.
Let us know the specifics. Thanks. 🙂
June 18, 2021 at 7:23 am #1826472Jim
Sorry, I don’t quite understand “with part of the post type and which part page”. The post type is page, and I’m talking about the main content.
I simply want to start off with a template that has the following, then for each individual page, I would fill in unique content under each heading and maybe delete or add headings, etc.
div class="wp-block-image small-pic"><figure class="alignright size-large"><noscript><img width="140" height="129" src="https://forestpathology.org/wp-content/uploads/2021/01/triangle-host.png" alt="" class="wp-image-6884"/></noscript><img width="140" height="129" src='data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20140%20129%22%3E%3C/svg%3E' data-src="https://forestpathology.org/wp-content/uploads/2021/01/triangle-host.png" alt="" class="lazyload wp-image-6884"/></figure></div> <h2>Host</h2> <p></p> <div class="wp-block-image small-pic"><figure class="alignright size-large"><noscript><img width="140" height="129" src="https://forestpathology.org/wp-content/uploads/2021/01/triangle-pathogen.png" alt="" class="wp-image-6885"/></noscript><img width="140" height="129" src='data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20140%20129%22%3E%3C/svg%3E' data-src="https://forestpathology.org/wp-content/uploads/2021/01/triangle-pathogen.png" alt="" class="lazyload wp-image-6885"/></figure></div> <h2>Pathogen</h2> <p></p> <div class="wp-block-image small-pic"><figure class="alignright size-large"><noscript><img width="140" height="129" src="https://forestpathology.org/wp-content/uploads/2021/01/triangle-environment.png" alt="" class="wp-image-6883"/></noscript><img width="140" height="129" src='data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20viewBox=%220%200%20140%20129%22%3E%3C/svg%3E' data-src="https://forestpathology.org/wp-content/uploads/2021/01/triangle-environment.png" alt="" class="lazyload wp-image-6883"/></figure></div> <h2>Environment</h2> <p></p> <h2>Disease Cycle</h2> <p></p> <h2>Signs and Symptoms</h2> <p></p> <h2>Distribution and Damage</h2> <p></p> <h2>Management</h2> <p></p> <h2>Other Issues</h2> <p></p>June 18, 2021 at 9:38 am #1826793David
StaffCustomer SupportHi there,
Block Templates are not a native part of WordPress as of yet – to do that requires Custom Development. Theres an article hear that provides some info on how to do that.
https://www.billerickson.net/gutenberg-block-templates/
The alternative, today, is to save a Re-usable Block with that content, add the re-usable Block and covert it to a regular block for making changes.
June 18, 2021 at 11:48 am #1826930Jim
Ok, thanks, good to know. The way I’ve been doing it so far is some lengthy code in functions.php I found in a tutorial to allow duplication of pages. So I have the “template” as a privately published page, and duplicate it. It works fine, but I worry about all that code breaking someday, and need to remember to make the copy public and edit the slug.
Thanks for the idea about reusable block – an alternative if the duplication code goes belly up.
June 19, 2021 at 4:32 am #1827431David
StaffCustomer SupportNo problems 🙂
Noticed i forgot to provide the article link above…. now added -
AuthorPosts
- You must be logged in to reply to this topic.