I am creating a one page wordpress site. The code I am using does work but for some reason it will not include page templates. It only gets the content from the page editor but will not get the custom html that is inside the page template so I am trying to include the file.
I am getting error messages that say include() : “Failed opening”
$template = get_post_meta( get_the_ID(), '_wp_page_template', TRUE );
$file = get_template_directory_uri() . '/' . $template;
include($file);
I am confused here because the path that it is giving me is the correct path for the file. I have 4 templates in my theme and from the code above, One template did get included but the other three have failed.
I think you meant to use:
instead of:
if you’re using
include()
for PHP code.But you should rather consider using:
The function
get_template_part()
is also handy when want to resuse template parts.