我需要更改WP_query
的行为。目前它显示了所有主要类别及其子类别,我需要具有特定类别及其类别。
例如:ID1的类别A有10个子类别,我需要显示(过滤类别A和10个子类)。
<?php
$the_query = new WP_Query( array("post_type"=>"project_post") );
while ( $the_query->have_posts() ) : $the_query->the_post();
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'project_preview_big' );
$image = $image[0];
$categories = wp_get_post_terms($post->ID,"projects_category");
$category = array();
if(count($categories)){
foreach($categories as $categ){
array_push($category,$categ->name);
}
$category = implode(",",$category);
}
else{
$category = "";
}
$cats = array();
foreach($categories as $cat){
array_push($cats,$cat->term_id);
}
$cats = implode(",",$cats);
?>
<div class="project" style="overflow:hidden;" data-categories='<?php echo $cats; ?>'>
<img src="<?php echo $image; ?>" width="100%"/>
<div class="project_box_info">
<p class="project_category_post"><?php echo $category; ?></p>
<h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
<p>
<?php
$content = excerpt(strip_tags($post->post_content),16,"...");
echo $content;
?>
</p>
<a class="read_more" href="<?php the_permalink(); ?>"><?php _e("Prohlédnout projekt","um_lang"); ?> <span></span></a>
</div>
</div>
<?php
endwhile;
?>