2012-02-07 60 views
0

这一直发生,我认为这是一个简单的PHP错误,我正在做,我不能为我的生活找到这本手册! 的PHP是这样的:为什么这个php字符串以错误的顺序显示?

echo '<h2 class="term-title">Search Results for '.the_search_query().'</h2>'; 

事实证明,这样的(当我搜索了大蒜):

<br/> 
garlic<br/> 
<h2>Search Results for</h2> 

我试过相同的代码的几个变化:

$title='<h2>'; 
$title .=the_search_query(); 
$title .='</h2>'; 
echo $title; 

显示是一样的。我试过<范围内的>标记 - 始终是相同的输出。

我在做什么错?

+0

这实在是模糊的。它应该如何出现以及它是如何出现的。搜索查询是做什么的? – 2012-02-07 04:23:18

+0

仅供参考 - ['the_search_query()'](http://codex.wordpress.org/Function_Reference/the_search_query) – Phil 2012-02-07 04:32:34

回答

0

是您的the_search_query()函数返回一个值,还是直接回显它获得的所有值?

例如:

function the_search_query() 
{ 
return $result; 
} 

function the_search_query() 
{ 
echo $result; 
} 

这似乎是相同的。 但直接回显功能结果有时会显示正确输出结果。

+0

您不应该使用淫秽表达式。 – Cheery 2012-02-07 04:32:13

+0

编辑。感谢提醒。 – wargodz009 2012-02-07 04:43:20

+0

['the_search_query()'](http://codex.wordpress.org/Function_Reference/the_search_query)是一个内置的Wordpress函数 – Phil 2012-02-08 00:41:57

5

与许多(可怕的)Wordpress功能一样,我假设the_search_query_that_you_searched_for_lol_kthxbye()执行echo。此echo将作为echo语句的一部分进行评估,因此首先出现在输出缓冲区中。

使用get_search_query()代替或者实现你原来这样的代码

<h2 class="term-title">Search Results for <?php the_search_query() ?></h2> 
相关问题