• 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)
  • 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.) 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.

    Thread Starter waveminded

    (@waveminded)

    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?

    I already told you… get_the_title

    Thread Starter waveminded

    (@waveminded)

    nice, it worked…

    so for the category I guess it would be

    get_the_category();

    Sort of, but that won’t work quite the way you think it will. read about 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 more generally.

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

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