0

我在 Wordpress 中使用以下简码:

function customquery() {
  query_posts('cat=18&tag=mytag');
}
add_shortcode('query', 'customquery');

以上工作正常。我需要“标签”来接受来自 URL 查询字符串的参数。我试过这个:

query_posts('cat=18&tag='.$_GET["tag"].'''');

这打破了页面。由于这是简码,我不确定是否需要将某些内容作为函数参数传递。但是,我看不到 .$_GET["tag"] 可以作为参数执行。我还能怎么做?

4

2 回答 2

2

试试这个

$my_tag = '';

if(isset($_GET['tag'])) {
  $my_tag = urlencode($_GET["tag"]);
}

$query_str = "cat=18&tag=" . $my_tag;

query_posts($query_str);
于 2013-03-15T03:53:39.240 回答
1

试试这个:

query_posts('cat=18&tag='.urlencode($_GET["tag"]));
于 2013-03-15T04:09:39.797 回答