have_posts()): while ($posts->have_posts()): $posts->the_post(); $random_color = $this->generate_random_color(); // get random color $counter++; if ($counter === 1): ?>
<?php the_title(); ?>
term_id)) . '">' . esc_html($categories[0]->name) . ''; } ?>

'; } ?>
<?php the_title(); ?>
term_id)) . '"'; if ('true' === $random_color_switch) { echo ' style="background-color: ' . $random_color . '"'; } echo '>' . esc_html($categories[0]->name) . ''; } ?>

current_post + 1 === $posts->post_count): echo '
'; endif; endif; endwhile; wp_reset_postdata(); // Reset after the custom query loop else: echo '

No posts found.

'; endif; ?>