• Resolved joshuatw

    (@joshuatw)


    I want to add a php include to my template. I want it to include a file called the title of the post. I’ve tried several thing, but I quite honestly don’t have any programming abulity. The most progress I made is using the following code:

    ‘<?php
    $startinclude = “<?php include(‘http://www.joshuatwood.com/includes/&#8221;;
    $endinclude = “.php’); ?>”;
    echo $startinclude;
    $thumbs = the_title();
    echo $endinclude;
    ?>’

    This returns to proper code for an include, but is not parsed by the server. Any ideas?

Viewing 6 replies - 1 through 6 (of 6 total)
  • You’re not using include properly, what that code will do is write the contents to the page sent to the browser. You want to do this:

    <?php
    include('http://www.joshuatwood.com/includes/' .the_title(). '.php');
    ?>

    I am not a coder by any means but… you should never use a URI in an include, only path.

    Thread Starter joshuatw

    (@joshuatw)

    That didn’t work either. I’m getting an error message saying that “.php” doesn’t exist, with the name of the post preceding the warning message.

    Just out of curiosity, why is it bad to use the URI in an include?

    As I said, not being a coder I just rely on what the coder gurus are saying here in the forum.
    And having spent a lot of time around here, I saw many times this warning from coders that I trust.

    Thread Starter joshuatw

    (@joshuatw)

    I got it figured out… I was staring at the code and realized that the “the_title()” function was calling another function and tried it… This is how I got it to work…

    include(‘../includes/’ .get_the_title(FALSE). ‘.php’);

    look strange. l am also looking something like that.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘PHP include containing a posts title.’ is closed to new replies.