我有一个问题:显示归档(在下拉列表)和一个页面内类别(在下拉列表)
我有一个存档模板页面,并在那里我想显示两个下拉菜单:归档和分类下拉列表,并当我点击例如存档为11月份,那么所有项目将从11月份的侧面显示,并且它也可以运行...但是,如果您选择了一个菜单项目,则将显示所有项目,而不仅仅是此类别的项目。
这里是代码:
在archives.php谈到这个代码(在这里是正确的...我认为):
<div id="archive-browser">
<div>
<h4>Month</h4>
<select id="month-choice">
<option val="no-choice"> — </option>
<?php wp_get_archives(array(
'type' => 'monthly',
'format' => 'option'
)); ?>
</select>
</div>
<div>
<h4>Category</h4>
<?php
wp_dropdown_categories('show_option_none= -- ');?>
</div>
</div>
<div id="archive-wrapper">
<div id="archive-pot">
</div></div>
而在其他的模板,名为档案的getter .PHP谈到这段代码,这里是什么地方的错误:
<?php
/*
Template Name: Archives Getter
*/
$year = htmlspecialchars(trim($_POST));
$month = htmlspecialchars(trim($_POST));
$cat = htmlspecialchars(trim($_POST));
$querystring = "year=$year&monthnum=$month&cat=$cat&posts_per_page=-1";
query_posts($querystring);
?>
<?php if (($year == '') && ($month == '') && ($cat == '-1')) { ?>
<table id="archives-table"><tr><td style='text-align: center; font-size: 15px; padding: 5px;'>Please choose from above.</td></tr></table>
<?php } else { ?>
<table id="archives-table">
<?php
if (have_posts()) : while (have_posts()) : the_post(); ?>
<tr>
<td><img src="<?php echo get_post_meta($post->ID, 'PostThumb', true); ?>" alt="" style="width: 35px;" /></td>
<td><a href='<?php the_permalink(); ?>'><?php the_title(); ?></a></td>
<td><?php comments_popup_link(' ', '1 Comment', '% Comments'); ?></td>
<td><?php the_date('m/j/Y'); ?></td>
</tr>
<?php
endwhile; else:
echo "<tr><td style='text-align: center; font-size: 15px; padding: 5px;'>Nothing found.</td></tr>";
endif;
?>
</table>
<?php } ?>
这两者连接在一起,所以当我运行档案模板,它从吸气调用数据。
我认为这个错误在querystring的某处...只有类别下拉菜单显示不是帖子。谢谢你的帮助。
谢谢,但存档下拉正常工作......然而类别下拉菜单可显示未在她的类别后,当我在类别XY点击。这里是jQuery代码,因为它是与此和后场的名称连接:
和后场的名字有我改变了:
$year = htmlspecialchars(trim($_POST['year_y']));
$month = htmlspecialchars(trim($_POST['month_m']));
$cat = htmlspecialchars(trim($_POST['cat_c']));
jQuery(function() {
jQuery("#archive-wrapper").height(jQuery("#archive-pot").height());
jQuery("#month-choice").change(function() {
// Update category choice dynamically
// This is much harder, needs another intermediary getter
});
jQuery("#archive-browser select").change(function() {
jQuery("#archive-pot")
.empty()
.html("<div style='text-align: center; padding: 30px;'><img src='' /></div>");
var dateArray = jQuery("#month-choice").val().split("/");
var y = dateArray[3];
var m = dateArray[4];
var c = jQuery("#cat").val();
jQuery.ajax({
url: "/archive-getter/",
dataType: "html",
type: "POST",
data: ({
"year_y": y,
"month_m" : m,
"cat_c" : c
}),
success: function(data) {
jQuery("#archive-pot").html(data);
jQuery("#archive-wrapper").animate({
height: jQuery("#archives-table tr").length * 50
});
}
});
});
});
您应该编辑您的问题或添加评论。当它不是答案时,不要将其作为答案添加。除了我没有更正下拉菜单之外,我更正了发布到帖子查询中的值,这是显示您说的帖子不起作用的部分。我将编辑我的答案,以包含你在这里提到的新的_post名称 – 2012-07-15 23:59:03