I am working on a WP theme and stumbled into a specific task which I can't describe here but I am sure if I show some screenshots here then you can understand the issue.
First of all please see the below image for posts div structure
It is the actual design from HTML, and specifically the first 2 posts inside a div and the third post inside another div like the below screenshot
please put a comment if you can't understand this.
The question is how to loop that dynamically by keeping the same structure and design?
And here is my codes below
<div class="row justify-content-center">
<div class="col-xl-3 col-lg-6 col-md-6">
<?php
while($projects_array->have_posts()):
$projects_array->the_post();
$idd = get_the_ID();
$terms = wp_get_post_terms(get_the_ID(), 'project_cat');
$output = array();
if ($terms) {
$i = 1;
foreach ($terms as $term) {
if($i == 1):
$output[] = '<span class="tag-'.$i.'">'.$term->name.'</span>';
$id[] = $term->term_id ;
endif;
$i++;
}
}
if ( class_exists('ACF') && get_field('choose_link_type') == 1 ) {
$post_link = get_the_permalink();
} else {
$post_link = get_field('external_link');
}
?>
<div class="single-portfolio-box">
<?php if(has_post_thumbnail()): ?>
<img src="<?php the_post_thumbnail_url(); ?>" alt="<?php the_post_thumbnail_caption(); ?>">
<?php endif; ?>
<div class="content">
<h3><a href="<?php echo esc_url( $post_link ); ?>"><?php the_title(); ?></a></h3>
<?php echo join( ' ', $output ); ?>
</div>
</div>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</div>
</div>
Thanks in advance.

