Title: php question include statement with variable
Last modified: August 19, 2016

---

# php question include statement with variable

 *  [waveminded](https://wordpress.org/support/users/waveminded/)
 * (@waveminded)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-include-statement-with-variable/)
 * Trying to figure out a simple fix and my PHP is not up to par… I’m trying to 
   create a dynamic include statement so that the page you are on generates the 
   appropriate side bar. Example:
 * <?php
    $page = the_title(); $sidebar = “Sidebar.php”; $combine = $page . $sidebar;
   include($combine); ?>
 * So if you’re on the index page
    the_title() = index
 * I want ‘index’ to combine with ‘Sidebar.php’ to form:
    indexSidebar.php
 * the include statement would look like this in a page source view:
 * include(‘indexSidebar.php’);
 * ***when I replace the include statement with:
 * echo $combine
 * the result is: indexSidebar.php
 * its breaking when I try to pass the $combine variable in the include statement…

Viewing 5 replies - 1 through 5 (of 5 total)

 *  [Adam Brown](https://wordpress.org/support/users/adamrbrown/)
 * (@adamrbrown)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-include-statement-with-variable/#post-681399)
 * A few problems. First:
 * `$page = the_title();`
 * `the_title()` does not return anything. It only prints. (If you don’t understand
   the difference, [read this](http://adambrown.info/b/widgets/easy-php-tutorial-for-wordpress-users/).)
   You could use `get_the_title()` if you want.
 * Second:
 * `the_title() = index`
 * No, that’s not what the value would be. Even if you used get_the_title, the value
   wouldn’t be “index,” it would be the name of a post.
 * Looks like what you really want is [Conditional Tags](http://codex.wordpress.org/Conditional_Tags).
 *  Thread Starter [waveminded](https://wordpress.org/support/users/waveminded/)
 * (@waveminded)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-include-statement-with-variable/#post-681401)
 * So how would you pass the static page title.. lets say the ‘about’ page into 
   a variable or
 * on a blog page I would want to pass the ‘category’ as the variable dynamically?
 *  [Adam Brown](https://wordpress.org/support/users/adamrbrown/)
 * (@adamrbrown)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-include-statement-with-variable/#post-681402)
 * I already told you… [get_the_title](http://codex.wordpress.org/Template_Tags/get_the_title)
 *  Thread Starter [waveminded](https://wordpress.org/support/users/waveminded/)
 * (@waveminded)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-include-statement-with-variable/#post-681403)
 * nice, it worked…
 * so for the category I guess it would be
 * get_the_category();
 *  [Adam Brown](https://wordpress.org/support/users/adamrbrown/)
 * (@adamrbrown)
 * [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-include-statement-with-variable/#post-681405)
 * Sort of, but that won’t work quite the way you think it will. [read about get_the_category](http://codex.wordpress.org/Template_Tags/get_the_category).
 * But it really sounds like you might be better off with the conditional tags that
   I mentioned earlier.
 * You should also look at [Template_Tags](http://codex.wordpress.org/Template_Tags)
   more generally.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘php question include statement with variable’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [Adam Brown](https://wordpress.org/support/users/adamrbrown/)
 * Last activity: [18 years, 4 months ago](https://wordpress.org/support/topic/php-question-include-statement-with-variable/#post-681405)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
