• Resolved PRuddyArt

    (@pruddyart)


    What I’m trying to do is create a new page template with no title and header area to use on the static front page, and perhaps use on other pages. I’m customizing TwentyTwenty via my own child theme (but I don’t think my issue is theme specific and I can’t seem to post in the theme support forum anyway, so I’m here)

    I’ve created a template-noheader.php page in a templates folder for my child theme with the comments at the top so it comes up as an option when I’m editing the page.

    This seems to work, text I add on this page to test it appears on my site.

    The problem is when I try to call the template part content-noheader.php within the template. I’ve based this off of the templates with the twentytwenty theme and plan to edit it. But text I put on this page doesn’t appear on my site.

    File structure: templates/template-parts/content-noheader.php
    I tried this first: get_template_part( ‘template-parts/content-noheader’);

    But found that it didn’t display any of the content – so the page consisted of the site header and the footer.

    When I was searching around for a solution I came across this syntax:
    get_template_part( ‘template-parts/content’, ‘noheader’ );

    At first I thought this had worked, but when I started to edit content-noheader.php the changes didn’t appear, so I think it is still pulling the parent theme’s default content file.

    I’ve tried assigning the template to the about page as well just in case the the index.php in the parent theme was overriding. But it doesn’t work there either.

    I know I’m probably missing something as I haven’t played around with page templates before. I’ve previously removed titles with css but I also don’t want the area it would appear in to be displayed at all and having a template that I could choose to use on other pages seemed to be a neat solution.

    Any pointers would be appreciated.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Good on you for trying to learn this on your own!
    But Twenty Twenty is a bad choice for learning page templates. The way it is structured is not very good, since it has very few template files and a lot of if statements in each one.

    The trick for child themes is to structure the folders the same way as the parent.
    For Twenty Twenty, there is a templates folder and there is a template-parts folder. They are at the same level.
    Page templates can be in the theme folder or in a subfolder.
    Template parts need to be in the same structure as the parent theme. Either one of your ways of calling get_template-part would have worked, but your template-part folder is under templates, so it could not be found.

    Thread Starter PRuddyArt

    (@pruddyart)

    Thanks Joy! That’s solved it! Bit daft that I hadn’t spotted they were on the same level, I figured it was something like that and kept checking the spellings!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Post Templates: get_template_part in a Child Theme’ is closed to new replies.