在页面中的wordpress中打印一个值

时间:2013-09-18 09:47:10

标签: php wordpress

你好我试图从WordPress网站上的页面中的URL打印一个值

我编辑了header.php并输入了以下代码

<?php
$town = rawurldecode( $_GET['town'] ); ?>
页面上的

我要打印我添加的值

<?php print $town ?>

我已经尝试了一些允许在页面中使用php的插件,但是我得到了错误

网址看起来像这样

website.co.uk/page/?town=abc

我尝试的结果是在页面中需要时使用PHP标记

例如

Hello i live in <?php print $town ?>, would you like to 
come see the football in <?php print $town ?>?.

Did you know that <?php print $town ?> is not that far?

2 个答案:

答案 0 :(得分:1)

您可以随时尝试使用get_query_var()

像这样:

 $town = get_query_var('town');
 echo $town; 

答案 1 :(得分:0)

更改

$town = rawurldecode( $_GET['town'] );

if(isset($_GET['town'])) { $town = rawurldecode( $_GET['town'] ); } else { $town = "No town"; }

并改变

<?php print $town ?>

<?php echo $town; ?>

也许这会奏效,请告诉我们结果。