'cat' => 4 // li add class mafs
'cat' => 5 // li add class reconstruction
'cat' => 6 // li add class stock
'cat' => 7 // li add class monolithic
<ul class="projects">
<?php
$args = array (
'post_type' => 'project',
);
$cat_one = new WP_Query( $args );
while ( $cat_one->have_posts() ) :
$cat_one->the_post();
echo '<li class="projects__item ';
if (get_category('4')) {
echo 'mafs';
} elseif (get_category('5')) {
echo 'reconstruction';
} elseif (get_category('6')) {
echo 'stock';
} elseif (get_category('7')) {
echo 'monolithic';
}
echo '">';
the_post_thumbnail('full', array('class' => 'projects__img'));
echo '<h3 class="projects__title">';
the_title();
echo '</h3>';
echo '<a href="'.get_permalink().'" class="projects__link"></a>';
echo '</li>';
endwhile;
?>
</ul>
<?php
$args = array (
'post_type' => 'project',
);
$cat_one = new WP_Query( $args );
while ( $cat_one->have_posts() ) :
$cat_one->the_post();
echo '<li class="projects__item ';
$categories = get_the_category();
$category_id = $categories[0]->cat_ID;
if ($category_id == 4) {
echo 'mafs';
} elseif ($category_id == 5) {
echo 'reconstruction';
} elseif ($category_id == 6) {
echo 'stock';
} elseif ($category_id == 7) {
echo 'monolithic';
}
echo '">';
the_post_thumbnail('full', array('class' => 'projects__img'));
echo '<h3 class="projects__title">';
the_title();
echo '</h3>';
echo '<a href="'.get_permalink().'" class="projects__link"></a>';
echo '</li>';
endwhile;
?>
function check_category () {
$categories = get_the_category();
switch ( $categories[0]->term_id ) {
case 4:
echo 'mafs';
break;
case 5:
echo 'reconstruction';
break;
case 6:
echo 'stock';
break;
case 7:
echo 'monolithic';
break;
}
}
implode()
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
$classes = array();
$classes[] = 'projects__item';
if ( $categories = get_the_category() ) {
foreach ( $categories as $key => $category ) {
$classes[] = $category->slug;
}
}
echo '<li class="' . esc_attr( implode( ' ', $classes ) ) . '">' . get_the_title() . '</li>';
}
}