2013-03-28 35 views
2

我对PHP和wordpress很新。我使用一个名为“PHP Execution”的插件来让我的php代码在wordpress上运行。但是当我把我的php代码放在单词按下并按下一个按钮来计算时,它会显示错误页面(404 — Fancy meeting you here!),并且不显示我的代码的结果。如何让php在wordpress上工作?

以下是我发布的WordPress的页面上的代码:

<?php 
isset($_POST['name']) ? $name = $_POST['name'] : $name = "empty"; 
isset($_POST['age']) ? $age = $_POST['age'] : $age = 0; 
?> 
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> 

Enter the name:<input type="text" size="12" size="50" name="name"><br /> 
Enter the age:  <input type="text" size="12" size="90" name="age"><br /> 
<input type="submit" value="Pin It" name="submit"> 

</form> 

<?php 
echo "the name: " . $name . "<br />"; 
echo "the age: ", $age; 
?> 

结果: enter image description here


把值在名称字段和年龄字段后, 按"Pin It"按钮:

enter image description here

+0

也许你想使用eval()? – Herr 2013-03-28 11:35:34

+0

查看此... http://wordpress.org/support/topic/404-error-when-previewing-a-post – 2013-03-28 11:37:06

+0

重新安装wordpress 3.5 ...检查出这个链接... http://codex.wordpress .org/Updating_WordPress#Manual_Update – 2013-03-28 12:00:58

回答

0

我认为在Post Entry字段中直接使用PHP代码并不是最好的办法。相反,你可以做到以下几点:

重复page.php文件并将其重命名为页custom.php

打开页面custom.php和替换这样的:

* The template for displaying all pages. 

下列要求:

* Template Name: Custom Template Justin 

您刚制作了一个自定义模板。你可以在你想在稍后显示的page-custom.php中输入你的PHP代码。

现在......当你创建或从WordPress管理编辑页面,在右侧你会看到选项模板,选择自定义模板贾斯汀从下拉列表并查看您的网页。

您的PHP代码应该在那里执行。