WordPress.org

Ready to get started?Download WordPress

Forums

Using PHP inside a custom page (5 posts)

  1. www.onlinecasinoselite.com
    Member
    Posted 6 years ago #

    I have a php page which submits to itself. If there is no POST data, it displays a form which then allows you to input values. If you submitted data to it, it does some functions based on that data and outputs that. Right now it's just plain text and pretty dull, and I wanted to include it as one of my WP pages. If I copy/paste the php and html inside a page, though, it prints out the form but the php is handled as regular text. Is there any way of including this form to make it fit in with the rest of my theme?

  2. whooami
    Member
    Posted 6 years ago #

    of course..

    some ppl are going to ell you to go find a plugin that lets you use PHP within pages..

    I say meh.

    You have a page, lets call it myform.php

    Put myform.php in the root of your WP folder (where wp-config.php is)..

    At the top of myform.php, put this:

    <?php
    require('./wp-blog-header.php');
    ?>

    You are then free to use ANY wordpress functions you like.. including

    get_header(); which will apply the header.php for your theme..

    get_sidebar(); which grabs your sidebar.php

    get_footer(); you guessed it -- thats your themes footer.php

  3. kristarella
    Member
    Posted 6 years ago #

    Or make it a page template!

  4. mrmist
    Forum Janitor
    Posted 6 years ago #

    I'd use the page template method if I wanted to make multiple pages which use the same set of PHP code to do something. For just one page, whoami's method is probably sharpest.

  5. www.onlinecasinoselite.com
    Member
    Posted 6 years ago #

    I ended up just copying page.php from my theme and grabbing the php form via the IFRAME tag. It took a little finagling (with the css property height) to get it to look right, but now it fits in great. Thanks everybody.

Topic Closed

This topic has been closed to new replies.

About this Topic