我不太了解wordpress,但我真的需要了解这个问题。该页面显示类别列表,位于条目的底部。当您单击列时,条目应该排序,它可以工作,但只显示标题,没有指向条目的链接,以及图片和摘录,日期,段。 enter image description here
<ul class="p-list">
<?php
if( $terms = get_terms( 'category', 'orderby=name' ) ) :
foreach ($terms as $term) :
echo '<li data-termid="'. $term->term_id .'">' . $term->name . '</li>';
endforeach;
endif;
?>
</ul>
<?php
query_posts( array(
'post_type' => 'post'
) );
if( have_posts() ){
while( have_posts() ){
the_post();
$i = get_the_post_thumbnail_url();
?>
<div class="project">
<a href="<?php echo get_permalink(); ?>"><div class="project-img" style="background: url('<?php echo $i;?>')"></div></a>
<span><?php the_title(); ?></span>
<?php the_excerpt(); ?>
<p class="post-date"><?php the_date('d/m/Y'); ?></p>
</div>
<?php
}
} else {
}
?>
这里是用于排序的js代码
$('#filter .p-list li').click(function(){
var that = this;
var filter = $("#filter");
var datas = {
action: 'myfilter'
};
if($('section').is('.may.blog')){
datas['postcat'] = jQuery(that).data("termid");
}else{
datas['foliocat'] = jQuery(that).data("termid");
}
console.log(datas);
$.ajax({
url:filter.attr('action'),
data: datas,
type:filter.attr('method'),
beforeSend:function(xhr){
filter.find('#response').text('Loading...');
},
success:function(data){
$('#response').attr("data-curcat", jQuery(that).data("termid"));
$('#response').html(data);
}
});
和functions.php
function true_filter_function(){
// для таксономий
if(!empty($_POST['foliocat'])) :
$args['tax_query'][] = array(
'taxonomy' => 'folio_cat',
'field' => 'id',
'terms' => $_POST['foliocat']
);
endif;
if(!empty($_POST['postcat'])) :
$args['tax_query'][] = array(
'taxonomy' => 'category',
'field' => 'id',
'terms' => $_POST['postcat']
);
endif;
$query = new WP_Query( $args );
if(!empty($_POST['foliocat'])) {
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post();
echo '<div class="portfolio"><a href="'.get_the_permalink(get_the_ID()).'"><div class="portfolio-img" style="background:url('.get_the_post_thumbnail_url().')"></div></a>';
echo '<p>'. get_field('folio_desc') .'</p>';
echo '<h4>'. get_the_title() .'</h4></div>';
endwhile;
wp_reset_postdata();
else :
echo 'No posts found';
endif;
}
if(!empty($_POST['postcat'])) {
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post(); ?>
<div class="project">
<div class="project-img"></div>
<p><?php the_title(); ?></p>
</div>
<?php endwhile;
wp_reset_postdata();
else :
echo 'No posts found';
endif;
}
echo '<div id="maxpagecat" data-maxpagecat="'. $query->max_num_pages .'"></div>';
die();
}
add_action('wp_ajax_myfilter', 'true_filter_function');
add_action('wp_ajax_nopriv_myfilter', 'true_filter_function');