I'm using this code:
<?php include (TEMPLATEPATH . '/template.php'); ?>
... to pull in a template file, no problems here.
But now I would like to include a specific template file based on a custom field value.
This is the code I use to output the custom field value:
<?php echo $item['display_template_id']; ?>
So what I would like to achieve is to have the template id value attached to the file name.
Something like this:
<?php include (TEMPLATEPATH . '/templates/template-' . echo $item['display_template_id']'.php'); ?>
That way the user could for example make a selection of which template to be included.
I'm getting the following error with the above code:
syntax error, unexpected T_ECHO
Your help is much appreciated.
Francisco Javier Carazo Gil answers:
You don't need to use echo.
Francisco Javier Carazo Gil comments:
The string will be well formed:
<?php include (TEMPLATEPATH . '/templates/template-' . $item['display_template_id']'.php'); ?>
That didn't work unfortunately. Thank you for your reply though.
paul de wouters answers:
there's WordPress native function for including templates which has the advantage of first looking in child theme first if there is one, which means you can override the parent theme.
get_template_part('loop','home'); // looks for loop-home.php
Thanks Paul, I am aware of this function, but to my understanding this should only be used for true WordPress template parts, such as in your example a loop template.
In my case its just a php file with specific information.