tags:

views:

41

answers:

3

I am very new to WordPress, so I would appreciate some help.

I am using WordPress as a CMS, and I am trying to make the thing work so that when I select a page to edit, there is a special box where I can input PHP code that will execute on my page.

I have found the PHP exec plugin, which works perfectly, but I would like to keep the code out of my main text editor, out of the way of my client's careless fingers.

Any suggestions would be very, very appreciated. Thanks!

+1  A: 

You could create a template for each one, and include your PHP there.

Simply select the template from the page edit page.

But if you are only including a little PHP per page, you could get the slug via WordPress in your page template and act on it accordingly.

alex
I am simply trying to include a PHP variable for each page. Having a seperate template file for each page seems a very inelegant solution to me and cancels the benefits of using a CMS at all.
Squirkle
@Squirkle You never mentioned that in the OP, so I wasn't to know that is only one variable. Why do you only place one variable per page? In that case you could get the slug via WordPress in your page template and act on it accordingly.
alex
Your edit was not to the point, and neither was your comment. I was very clear that I want to create a custom metabox that can execute PHP FROM THE CMS. Please remove the downvote.
Squirkle
@Squirkle Do you think it is a good idea to run PHP that you've entered into the backend and then `eval()` it? Not for security concerns per se (though there are some, having code in the database, and WordPress often has security exploits), but because the maintainability suffers.If you did a switch case on the [page slug](http://snipplr.com/view/11411/wordpress-get-page-slug/) and then ran code in your `page.php` template, it would sound like a better solution.
alex
A: 

PHP Exec is the best plugin I have found, and I looked long and hard for that one. The problem with doing it as you suggest is that if the PHP code displays an item on the page, it still has to be formatted within the page as well. It is a simple logistical problem, but somewhat of a complex coding problem. I haven't been able to get around to working on creating a better plugin for it.

Joseph
A: 

You can also add an extra meta box on the post editor page, only visible to you, with a textarea where you can add the code. You would save it as a meta field of the post. Your template can check for the existence of this field, and execute it if found.

Jan Fabry
This looks like a possibility. I'm going to check and see if I can get it to execute the PHP inside of this.
Squirkle
You'll have to turn to `eval()` to run the code from a string.
alex