Site logo

[Support request] Custom page template

Home Forums Support [Support request] Custom page template

Home Forums Support Custom page template

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

    #1825919
    Ying
    Staff
    Customer Support

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

    #1825929
    Jim

    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?

    #1826060
    Elvin
    Staff
    Customer Support

    Hi 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 a str_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. 🙂

    #1826472
    Jim

    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>
    
    #1826793
    David
    Staff
    Customer Support

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

    #1826930
    Jim

    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.

    #1827431
    David
    Staff
    Customer Support

    No problems 🙂
    Noticed i forgot to provide the article link above…. now added

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