简体   繁体   中英

WordPress: Child theme + Custom Post Template

I'm building a WordPress site using Elementor theme. I'm quite new to WordPress development.

I'm using a custom post type for a group of entities. I need to create a custom post template for these. I'm using the default Hello Elementor theme. I've created a child theme, so that I'm not making code changes to the base theme, in order to avoid issues when updating.

In the child theme, I've created a template for the custom post type, using the structure described in the documentation here , by creating a file called single-{entity name}.php. This works, as I can modify this file, and it'll affect the results rendered when I try and access one of these pages.

My problem is that the header and footer disappears and it seems to disregard everything from the parent theme. If I copy this single-{entity name}.php file into the parent file, it works just as expected with the header and footer showing.

I'm guessing there's some logic that intercepts the render in the parent theme and adds the header and footer, but I don't know how it actually works.

I'm not sure whether I should keep it in the parent theme to get this to work of if I should move it back to the child theme and then add some configuration in order to get the header/footer to show? If the last option is the recommended way, guideline on how to achieve this.

Goal is to be able to have a file that governs the template for all entities of this type, keep the header/footer and not be at risk of breaking when updating the theme and/or WordPress.

Have you tried to copy an existing file (exact copy of single_post.php for example) just to see if it works ? If the page have header and footer, then the error is on this php file, otherwise it's somewhere else.

You can have an idea like that

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM