I'm working on my first wordpress site, and moving it online. I have been adding some extra templates to design a simple booking engine, that was working perfectly on my offline localhost server.
However, I've been having trouble with getting these templates and other .php-files to work on the live website. It seems that using a specific path to locate the template or file doesn't work; get_template_part()
and include()
can only load the template/file when it is in the same folder.
For example, I have a page template called 'Bevestigingstemplate.php' in my Child-theme's folder (Theme-child), that I activated on one of my web pages. In this template, I want to call a file called 'bevestiging.php', that's located in Theme-child/modules/content.
However, if I call get_template_part('modules/content/bevestiging')
OR include('modules/content/bevestiging')
, it fails and I get a broken page.
If however I move 'bevestiging.php' directly into my Child-theme's folder and call get_template_part('bevestiging')
, it works like a charm.
Now I don't want to end up with a chaotic list of templates and sub-templates in my Child-theme folder, so I'm desperately looking for a way to fix this. I've read somewhere that I should maybe add a config.php file in my Child-theme's folder that defines a 'root', but I couldn't find a clear walkthrough and was hoping to maybe fix it in an easier way, or at least first to understand where I'm going wrong here.
Any advice on how to proceed is welcomed warmly. Thanks!
Below is the code I use in Bevestigingstemplate.php (basically just copied page.php from main theme).
get_header(); ?>
<div id="primary" class="content-area <?php do_action('adviso_primary-width'); ?>">
<main id="main" class="site-main">
<?php
get_template_part('modules/content/bevestiging');
?>
</main><!-- #main -->
</div><!-- #primary -->
<?php
get_footer();
get_template_part()
would work but since your templates are in a child theme directory you have to provide that extra information.