这是我的页面ajax。php文件
define(\'WP_USE_THEMES\', false);
require_once(\'../../../wp-load.php\');
$terms = get_terms( \'bk-category\' );
foreach ( $terms as $term ) {
}
$bkcat = $term->term_id;
$args = array(
\'posts_per_page\' => -1,
\'category\' => $bkcat,
\'order\' => \'ASC\',
\'post_type\' => \'bk-post\',
);
$the_query = new WP_Query($args);
if($the_query->have_posts()) {
?>
$i = 1;
while($the_query->have_posts()) : $the_query->the_post();
$a = $i++;
endwhile;
}
这是我的页面表。php文件
global $post;
$terms = get_terms( \'bk-category\' );
$select = "n";
$select.= "Select categoryn";
foreach($terms as $term){
if($term->count > 0){
$select.= "slug."\'>".$term->name."";
}
}
$select.= "";
echo $select;
$(document).ready(function() {
var dropdown = document.getElementById("cat");
function onCatChange() {
if ( dropdown.options[dropdown.selectedIndex].value != -1 ) {
$(\'.results\').html("/images/loading.gif\' />");
$.ajax({
type: \'POST\',
async: true,
dataType : "html",
url: "/page-ajax.php",
success: function (data){
$(\'.results\').html(data);
}
});
}
}
dropdown.onchange = onCatChange;
});
在本例中,所有显示或所有类别显示,但是:我只想显示单击的每个类别的内容