tags:

views:

60

answers:

4

I want to create a custom page for my Wordpress blog that will execute my php code in it, whilst remaining a part of the overall site css/theme/design.

The php code will make use of 3rd party APIs (so I need to include other php files)

How do I accomplish this?

N.B. I do not have a specific need to interact with the Wordpress API - apart from including certain other php libs I need I have no other dependencies in the PHP code I want to include in a WP page. So obviously any solution that didn't require learning the WP api would be the best one.

+1  A: 

Hi, you can use those plugins : http://wordpress.org/extend/plugins/exec-php/ or http://wordpress.org/extend/plugins/php-code-widget/ Hope it will help!

Michaël
do these allow me to include external php files?
rutherford
you can include external php files, with the first plugin, using :<?php require_once(ABSPATH. 'example.php'); ?> (example.php must be store in the webserver root directory)See also the doc of Bluesome (first plugin) : http://bluesome.net/post/2005/08/18/50/#execute_php
Michaël
A: 

You will want to take a look in to WordPress' plugin API. This explains how to "hook" and "filter" in to different parts of the WordPress mechanics, so you can execute custom PHP code pretty much any where at any given time. This hooking, filtering, and custom code authoring can all take place in your functions.php file in any of your themes. Happy coding :)

hsatterwhite
I don't really want to interact with the Wordpress API itself though - my PHP code is completely independent of any WP shenanigans. But I do need to reference external php files.Are you sure the API is what I need to learn in this case?
rutherford
It all depends on what you're trying to do. Using the API can help in some cases and others be completely non-essential. It's all dependent on what you're trying to achieve. You could go with @adam's suggestion and use page templates or you could keep all of your custom code in one basket and then hook/filter in to different parts of WordPress.I'd say all and all, choose what works for your best and what you feel comfortable with. All three of these answers will accomplish what you want in one form or another.
hsatterwhite
+3  A: 

You don't need to interact with the API, or use a plugin.

First, duplicate post.php or page.php in your theme folder (under /wp-content/themes/themename/).

Rename the new file as templatename.php (where templatename is what you want to call your new template!). Enter the following at the top of the new file:

<?php
/*
Template Name: templatename
*/
?>

You can modify this file (using php) to include other files or whatever you need.

Then create a new page in your wordpress blog, and in the page editing screen you'll see a 'Template' dropdown in the 'Attributes' widget to the right. Select your new template and publish the page.

Your new page will use the php code defined in templatename.php

adam
Props to @adam -- this is the simpliest, easiest, and fastest way to do it.
hsatterwhite
Thanks! That's exactly what I needed.
Drew LeSueur
A: 

If you don't want to deal with WP API, then Adam's answer is really the best one.

If you were willing to deal with the API I would suggest hooking into the "template-redirect" hook, which would allow you to point a particular URL or page to an arbitrary PHP file while still having access to the WP.

Strider