Horje
Need Help With Syntax Error: syntax error, unexpected T_ECHO - Wordpress Solution
Hi, 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. Thanks!

Solution - 1

Use


<?php include (TEMPLATEPATH . '/templates/template-' . $item['display_template_id'] . '.php'); ?>
instead


Solution - 2

try this


<?php 
include (TEMPLATEPATH . '/templates/template-' . $item['display_template_id'] . '.php'); 
?>


Solution - 3

Just remove the echo keyword. Use this

<?php include (TEMPLATEPATH . '/templates/template-' .$item['display_template_id']'.php'); ?>


Solution - 4

You don't need to use echo.


Solution - 5

try this

Solution - 6

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('/path_to/template.php'); or get_template_part('loop','home'); // looks for loop-home.php http://codex.wordpress.org/Function_Reference/get_template_part





Wordpress

Related
Modify wp-signup.php - Wordpress Solution Modify wp-signup.php - Wordpress Solution
deactivate links to single post view  - Wordpress Solution deactivate links to single post view - Wordpress Solution
Finding colour tones... - Wordpress Solution Finding colour tones... - Wordpress Solution
Custom headers and custom image sizes - Wordpress Solution Custom headers and custom image sizes - Wordpress Solution
How do I set SITE_URL to override the database url info?  - Wordpress Solution How do I set SITE_URL to override the database url info? - Wordpress Solution

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
8