ok I’m creating a portfolio page. I want all the images of the portfolio post stack together. & when visitors hover their mouse in any of the title the image ll show.
for this I’ve created this loop:
<div class="main-interior portfolio" id="portfolio-big-pics" style="display: block;">
<?php $args = array( 'post_type' => 'portfolio', 'order' => 'ASC');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php $extraLastClass = $loop->current_post + 1 === $loop->post_count ? ' main-image-porfolio-main' : '';?>
<?php the_post_thumbnail( "thumbnail", array( "class" => "main-image portfolio $extraLastClass" ) ); ?>
<div class="portfolio-box">
<h5>Portfolio</h5>
<ul class="item-list" id="portfolio-list">
<li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
</ul>
</div>
<?php endwhile; ?>
</div>
as you can see my images & titles are within the loop. it prints out like: first image & first title, then second image & second title, third image+third title & so go on… what I want is print out all the images first & then the titles. like: first image, second image, third image & then first title, second title, third title. Basically from my code, all the images of the portfolio item ll load first & then the “portfolio-box” div. screenshot attached.
use
<?php rewind_posts(); ?>
What you want is so simple. Just get out the titles from the loop, and then create the same loop again, with titles. An alternative way, if you collect the data into an array in 1 loop, and use that to show images and then pictures, so you need to run only once the query.