Displaying multiple loops based off of category
Question
I have a blog feed loop that I want to change the style of a blog if it has a certain category. So if category x show this code structure otherwise continue with the the loop. The logic is simple I just have a very specific loop set up and syntactically don’t know how to add this in. Many thanks in advance:
<?php $catquery = new WP_Query(array(
'orderby' => 'date',
'order' => 'DESC'
)); ?>
<?php while($catquery->have_posts()) : $catquery->the_post(); ?>
<?php $backgroundImg = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large' );?>
<div class="row episodes-feed-wrap">
<div class="col-4 episodes-feed-thumb">
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php echo get_the_post_thumbnail( $post->ID, 'large' ); ?>
</a>
</div>
<div class="col-8 featured-article">
<div class="container" style="padding:0;">
<h4 class="episodes-feed-cat">
<?php $categories = get_the_category();
if ( ! empty( $categories ) ) {
echo '<a href="' . esc_url( get_category_link( $categories[0]->term_id ) ) . '">' . esc_html( $categories[0]->name ) . '</a>';
}?>
</h4>
<a href="<?php the_permalink() ?>" rel="bookmark">
<h2 class="episodes-title">
<?php the_title(); ?>
</h2>
</a>
<div class="episodes-excerpt">
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php echo excerpt(25); ?>
</a>
</div>
<div class="episodes-feed-info-wrap">
<div class="episodes-feed-author">
<a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_author(); ?> • <?php echo meks_time_ago(); /* post date in time ago format */ ?>
</a>
</div>
</div>
</div><!-- end container -->
</div>
</div>
<?php endwhile;
wp_reset_postdata();
?>
0
categories, feed, loop
3 years
2020-03-23T12:51:44-05:00
2020-03-23T12:51:44-05:00 0 Answers
90 views
0
Leave an answer