目标:我想创建一个动态页面,允许访问者从下拉菜单中选择月份和年份,并使页面上的内容(帖子)根据所选值更改.
我目前正在使用以下代码显示特定月份和年份的特定类别的帖子.
<?php query_posts("cat=3&monthnum=12&year=2011"); ?> <?php if (have_posts()) : ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li>
<?php the_title(); ?>
<?php the_excerpt(); ?>
</li>
<?php endwhile; ?>
</ul><?php endif; ?>
Run Code Online (Sandbox Code Playgroud)
它运行良好,但我想使页面动态,以便访问者可以从下拉菜单中选择月份和年份,并根据所选值更改内容.我已经发布了它在这里如何工作的图片:fivepotato.com/images/ex1.png和fivepotato.com/images/ex2.png.
为了使这项工作,我知道我必须使monthnum的值变为一个变量(取自下拉列表:
<?php $monthvar = $_POST["month"]; query_posts("cat=3&monthnum=$monthvar&year=2011");?>
Run Code Online (Sandbox Code Playgroud)
我对Ajax没有多少经验,但我认为我需要使用它来从下拉菜单中选择每月一次重新过滤内容.
我在以下网站上发现了类似的问题:askthecssguy.com/2009/03/checkbox_filters_with_jquery_1.html
我找到了一个类似于我想要做的工作示例:http://www.babycarers.com/search?ajax = 0&searchref = 37609&start = 0 &lat =&al =&city =&radius = 0&spec1 = 1&spece2 = 1&spec3 = 1&spec4 = 1&spec5 = 1&spec6 = 1&spec7 = 1&INST1 = 1&INST2 = 1&inst3 = 1&inst4 = 1&inst5 = 1&inst6 …