0

我有这个功能:

<?php
function getmypost($number)
    {
        query_posts('p=1828');
        while (have_posts()) : the_post();
        the_title('<h1>', '</h1>');
        the_content();
        endwhile;
    }
?>

我需要将 1828 作为变量我已经尝试过:

    query_posts('\'p='. $number .'\'');

但它不起作用。这样做的正确方法是什么?

4

2 回答 2

3

如果我理解正确

query_posts('p='.$number);

应该管用。

'如果您需要在字符串中使用单引号,则可以转义'

query_posts('p=\''.$number.'\'');

或使用双引号(更优雅,您可以直接输入变量。Dominik 已经在他的回答中提出了这一点)

query_posts("p='$number'");
于 2010-02-10T15:01:57.897 回答
0

你可以使用

query_posts("'p=$number'");
于 2010-02-10T15:05:41.243 回答