WordPress.org

Ready to get started?Download WordPress

Forums

can I run a PHP file from a wordpress page or post? (8 posts)

  1. edpattermann
    Member
    Posted 1 year ago #

    Hi.

    I am porting an existing (non-Wordpress) site to WordPress

    the existing site executes php files, with arguments, to return results from a MYSQL database. the results are output in an HTML table.

    a sample call would be something like this

    tour.php?style=&tour=Majors&name=&year=&tournament=British+Open&in=Career+Stats<

    i do not want to reinvent the wheel. A lot of work has gone into tour.php, and other files like it, on the existing site.

    can I execute that tour.php file, as in the above example, and return the results to a wordpress page?

    with static calls and arguments, or ones generated on the fly?
    any issues with performance?

    thank you.

    -- Ed

  2. jonradio
    Member
    Posted 1 year ago #

    WordPress Shortcodes are pretty close to what you are doing. If you convert tour.php into a plugin that defines a Shortcode called [tour], you will have pretty much the same as what you had on your non-WordPress site. And have the best combination of performance and ease of implementation.

    This might be a good place to start reading:
    http://codex.wordpress.org/Shortcode_API

  3. 101Phil
    Member
    Posted 1 year ago #

    Take a look at this plugin it may be what you are looking for.
    http://wordpress.org/extend/plugins/exec-php/

    I use it mostly in the form of putting small PHP snippets inside of a widget. You could look at creating a new page template with a widget area to house your tour functions.

    Then create a new page Tour (or what ever) and choose the Tour Template for that page.

    Could be a quick and easy solution for you.

  4. jonradio
    Member
    Posted 1 year ago #

    101Phil is right, in terms of quick implementation, but I made my recommendation based on performance.

    If you prefer 101Phil's approach, please also consider:
    http://wordpress.org/extend/plugins/shortcode-exec-php/
    I looked at all alternatives, including Phil's suggestion, and found this one offered the most security.

  5. edpattermann
    Member
    Posted 1 year ago #

    Thanks for all the responses so far. I am not dealing with small pieces of code, but large PHP files.

    So the idea of turning that code into a plugin sounds more reasonable.

    That is beyond my skill level though.

    Anyone out there want to help me?

  6. jonradio
    Member
    Posted 1 year ago #

    To convert a .PHP file into a shortcode inside a plugin, you make it into a function that returns rather than echos all its results. Then you do an add_shortcode to say that [myname] activates php function edp_myname() (be very carefuly to keep function names unique in WordPress by prefixing). A Plugin has a special header of comments at the beginning of its php file, and you can define as many shortcodes as you want in a single plugin.

    There are lots of details in codex.wordpress.org, but I personally found the concept of plugins too daunting so bought a book and was a lot happier when I first started. My fav. is Professional WordPress Plugin Development by Brad Williams, Ozh Richard and Justin Tadlock.

  7. 101Phil
    Member
    Posted 1 year ago #

    Nice one Jonradio,
    I think I'll use that suggested plugin too, next time round. or use your suggestion and go the short code route. Ps I have a post on here I'm stuck with, if you don't mind I will PM you for some advice.

    Keep us posted on your project Ed. Also if you dont have time/expertise, you could look at Freelancer.com (or insert other site here) as a way of getting the functionality built.

  8. jonradio
    Member
    Posted 1 year ago #

    101Phil: I have responded in the support thread for your problem that you are referring to.

Topic Closed

This topic has been closed to new replies.

About this Topic