【发布时间】:2012-10-10 20:27:39
【问题描述】:
这个棘手的问题让我很抓狂。我的网址是:www.mysite.com/page/?id=sun
我想获取变量 (sun) 并将其放入我的 PHP 数组中:
<?php
$tag = $_GET['id'];
wp_reset_query();
query_posts(array('post_type'=> 'projects','technologiestags'=> $tag) );
if(have_posts()):
while(have_posts()):the_post();
?>
<div class="technology">
<h4><?php the_title(); ?></h4><br/><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(''); ?></a>
</br></br><div class="readmore"><a href="<?php the_permalink(); ?>">Read more »</a></div>
</div><!--END of technology Id-->
<?php endwhile; endif; wp_reset_query();?>
如您所见,我使用了“.echo "$tag".”,但它不起作用。有没有其他方法可以获取 URL 变量并将其插入 PHP。
提前致谢。
【问题讨论】:
-
如果这确实是您的完整来源,请记住
if():和while():(冒号)需要关闭endif/endwhile语句。如果您真的想要单个语句体,请删除冒号。 -
嗨 lanzz,完整代码是: 'projects','technologiestags'=> $tag) ); if(have_posts()): 而(have_posts()):the_post(); ?>
-
嗯,很有帮助。考虑在您的问题中对其进行编辑。
-
抱歉,我已将完整代码添加到顶部的主问题框中...
标签: php arrays wordpress url variables