WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Embedding PHP Code (5 posts)

  1. gashbaugh
    Member
    Posted 8 years ago #

    Hi:

    I have some PHP script that I'm trying to include on one of my pages. I've downloaded and installed several plugins that parse the php like exec-php, and runphp, but they don't parse it correctly. If I put the PHP code in a blank page and run it directly (not having anything to do with WP), then it works fine.

    I was wondering if anyone has any other ideas I can try.

    Thanks.

  2. Michael Bishop

    Posted 8 years ago #

    Just to clarify, when you say "one of my pages" are you referring to Pages ?

    Generally speaking, you can create a Pages#Page_Templates and include your php within that. Then go to Write --> Page and create the page using your custom template.

    The template can either just be the script, or it can have some dynamic content you add via the write panel plus your php code, all depending on if you include the loop in the template.

    If after reading over those links, you have more questions, by all means, check back.

  3. gashbaugh
    Member
    Posted 8 years ago #

    Hi,

    Thanks for the reply. Yes I was referring to Pages.

    I never thought of putting the code in the Pages.php file, and I actually tested it and it works fine that way. Here is my only problem, I only want that code to show in a particular Page. I notice each Page has an ID assigned to it. Is there a way in my page.php file to say something like (if page id = 1) { display code here }?

    If I can do do that, what is the exact code to use for that? Thanks for the help. =)

  4. Michael Bishop

    Posted 8 years ago #

    take a look at the Pages Templates link again. You can create as many custom page templates as you desire. Then when you write page, you choose the particular template your code is on, instead of default.

    I'm working on my personal site and just about every "Page" is a different template.

  5. gashbaugh
    Member
    Posted 8 years ago #

    Okay I get it now. That is really helpful. I kept trying to find where to change the template, and finally read you actually need to upload one first. Good stuff.

    Thanks for your patience!

    Cheers.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags