我不知道我是否使用了这个问题的最佳标题,但我不确定如何用它来表达。我已在我的网站上成功设置了可过滤的投资组合脚本,但我需要为每个项目应用适当的类。现在我已经得到了这个。
<?php $loop = new WP_Query( array( 'post_type' => 'productions', 'posts_per_page' => -1 ) ); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="tile web all"> <?php the_post_thumbnail ( 'home-page' ); ?>
<a href="<?php the_permalink(); ?>" target="_blank"><h1><?php the_title(); ?></h1></a>
</div>
<?php endwhile; wp_reset_query(); ?>
班级&#34; web&#34;只是一个例子,它需要被用于特定帖子的类别的slug替换,因为我设置了过滤器以自动显示所有类别:
<div class="filters">
<p href="" data-rel="all">All</p>
<?php
$args = array(
'type' => 'productions',
'orderby' => 'name',
'order' => 'ASC',
'taxonomy' => 'production_type',
);
$categories = get_categories($args);
foreach($categories as $category) {
echo '<p data-rel="' . $category->slug.'">' . $category->name.'</p> ';
}
?>
希望这足以提供一些帮助。感谢。
答案 0 :(得分:0)
这有效:
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="tile <?php
$terms = get_the_terms( $post->ID , 'production_type' );
foreach ( $terms as $term ) {
echo $term->slug;
echo ' ';
}
?> all"> <?php the_post_thumbnail ( 'home-page' ); ?>
<a href="<?php the_permalink(); ?>" target="_blank"><h1><?php the_title(); ?></h1></a>
</div>
<?php endwhile; wp_reset_query(); ?>