WordPress.org

Ready to get started?Download WordPress

Forums

php includes in pages (13 posts)

  1. mango23
    Member
    Posted 8 years ago #

    How do I include a php include into a static page?

    thanks,

  2. What do you mean by a "static page"? Are you referring to a WordPress "Page" (which aren't static BTW) or a true static page like an .html document?

  3. lashout
    Member
    Posted 8 years ago #

    <?php include('filename'); ?>

    or

    <?php require_once('filename'); ?>

  4. mango23
    Member
    Posted 8 years ago #

    I mean the wordpress 'page'.

    when i add <?php include('filename'); ?> , it just puts that there and not the file.

  5. moshu
    Member
    Posted 8 years ago #

    Unless you run a plugin that allows for running PHP in posts and Pages - you can't.
    Here is one of those plugins: http://wordpress.org/support/topic/52928?replies=6

  6. lashout
    Member
    Posted 8 years ago #

    Ok you really need to link us to the page your tring to do this too...

    Also you can't just copy what I have and paste it in the post section of the site and it work. You will need to edit the template and then change the file name to the includes that you need.

    example

    <?php
    include('test.php');
    ?>

  7. moshu
    Member
    Posted 8 years ago #

    Using an "include" in a template or using php in a Page - those are two different things. My impression was the OP asked for a Page, not a template.

  8. lashout
    Member
    Posted 8 years ago #

    Yea I got that impression after I read the other post ...

  9. As said, you can't do PHP in posts. You'll need a PHP plugin or even better, make a custom Page template.

    http://codex.wordpress.org/Pages#Page_Templates

  10. mango23
    Member
    Posted 8 years ago #

    exactly , i was trying to add a php include into a 'page' and instead of the code running I got the text of the code.

    thanks moshu for your help.

    i was hoping it would be easier then creating a custom template with the code in it. But i guess the plugin might be easier so i will try that.

  11. Not hard. Just make a copy of your page.php and rename it to something else.

  12. moshu
    Member
    Posted 8 years ago #

    Plus add some lines at the top :)

  13. davidchait
    Member
    Posted 8 years ago #

    You can also try CG-QuickPHP for something THAT simple (i.e., one 'function' used, and 'static' variables...). The format would be like:

    <quickphp include('filename'); />

    Note of course that it's great if you know the absolute path to the file -- but not if you want to use PHP variables to determine a file path, etc.

    Just thought I'd toss in another (fast) option.

    -d

Topic Closed

This topic has been closed to new replies.

About this Topic