What would be the best (easiest) way to put PHP code on a WordPress “Page” feature (or even a Post, for that matter).
Using the WordPress interface to write a page or post doesn’t accept PHP code, as it tries to HTML-ize it or mangle it in other ways. Is this possible?
You need a plugin:
Look for php-exec, exec-php, run-php and similar stuff.
yes this is what i need, but now i get another problem…
when i use runPHP
i get the following problem
if fill in
$curDate = date(‘D., F jS Y H:i:s’);
echo ‘Right now the server thinks it is ‘ . $curDate;
then i check the checkbox ‘use runphp’
i save the page (publish)
when i watch the page i see this
wp deleted the upperpart of the php script,
so what do i do wrong now?! 🙁
if you’re having troubles, it is mentioned in a couple places that php_exec might work better for some folks than runPHP. even the author of runPHP says this….
now i get this error 🙁
Parse error: parse error, unexpected T_VARIABLE in /var/www/vhosts/ruunerwold.nl/subdomains/geenstress/httpdocs/wp-content/plugins/exec-php.php(75) : eval()’d code on line 52
it works fine normally…
If you’re using WP2.0, you’ll need exec-php as php-exec will cause you errors.
An even *better* way than using a plugin is to make a Page Template with the PHP code you want to use and then use that Page template for that page only. This requires no plugins and it is more secure than trying to stick PHP in a place where you don’t really want it (the database).
You’ll have to use a plugin to put code into a Post, however if you have to put code into a Post, then there’s probably a better way to do whatever it is that you’re trying to do, and you should reconsider and ask about that instead.
ok, 2 more questions, how can i get a link in the left menu to this new template
and why do i get this error
Fatal error: Call to undefined function: get_header() in /var/www/vhosts/ruunerwold.nl/subdomains/geenstress/httpdocs/wp-content/themes/fluidityls-10/snarf.php on line 6
when i just use the example!?
<?php get_header(); ?>
something wrong with this?
baszer: What “left menu” are you talking about? Page templates show up on the right hand side of the Write Page screen, under the “Page Template:” box. And you get them to show up there by simply creating them with the header as it shows in the example:
Template Name: Snarfer
As for the error, this is not a file you run *directly*. It’s a file that WordPress will use. The reason you get the error with get_header is because you are trying to call it directly. Don’t do that. Go to your Page and edit it, then choose your template from the drop down and save. Then that page will use your new template. And it won’t get that error.
check out “www.dynamicdrive.com” where you can find some script to make a sliding menu on the left side.
I’m trying to do something similar…include a gallery within a page. I got the php to run on the page, see here: http://www.divaknitting.com/blog/?page_id=334 but the problem comes when you try to click on a category. I got the page to show up by putting view.php in the blog directory but now I am at a loss as to how to get the blog to appear around it as you drill down to single pics. Any ideas?
I’ve got a page where I want a frequently-changing version number to appear. I’ve created a page template and I can get at the version number in the template using require_once, but I’m stumped re: how to get this version number from the page template into the page content.
If using a php plugin is the right way to do it then fine, just thought I’d ask if there was a better way.
Anything from a template should get into the Page if you are using that template when creating the Page.
Hm, a code sample might better illustrate my question.
Here’s an abbreviated bit of the template:
<?php require_once 'fooversion.inc.php'; ?> <?php the_content(); ?> <?php edit_post_link('Edit this entry.' . get_foo_version(), '<p>', '</p>'); ?>
and then the page appears (ignoring the sidebar):
Edit this entry 1.2.3
So I can make the version number appear in the post link. But I want the version number to appear inside the page content like this:
Edit this entry
In other words, I want the version number to appear within the page content and this is where I get stuck.
I am getting the feeling that the only way to get this version number into the page content is with a php plugin or at least something like the Enzymes plugin.
- The topic ‘Putting PHP on a WordPress “Page”’ is closed to new replies.