ok I have a portfolio page. & I have two question:

number 1: Every portfolio item has thumbnail attached. what I want is to print out the first thumbnail from the first post twice. One at the beginning & other at the ending. like: image_1, image_2, image_3, image_4 & image_1 again.

number 2: All my images have some id, like: id="photo_46", id="photo_47", id="photo_48" & so on... I want my last thumbnail(the thumbnail which I have repeated in the first stage at the end of the loop) to not have this id.

my code is:

<div class="main-interior portfolio" id="portfolio-big-pics" style="display: block;">
<?php $args = array( 'post_type' => 'portfolio', 'order' => 'dsc');
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post(); ?>

<?php $extraFirstClass = $loop->current_post == '0' ? ' main-image-porfolio-main' : ''; ?>

$attributes = array(
    "class" => "main-image portfolio " . $extraFirstClass,
    "id" => "photo_{$post->ID}",
the_post_thumbnail("portfolio_thumb", $attributes);

<?php endwhile; ?> 

<?php rewind_posts(); ?> 

    <div class="portfolio-box">
        <ul class="item-list" id="portfolio-list">
        <?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
        <li><a href="<?php the_permalink(); ?>" rel="<?php echo $post->ID; ?>"><?php the_title(); ?></a>
        <?php endwhile; ?>              


How can I solve this two problem? A live exmaple of what I'm trying to accomplish can be find here: http://kzarchitecture.com/portfolio/

1 Answer 1


You can rewind_posts() then just call $loop->the_post() once outside of the while loop, output the thumbnail, and rewind_posts() again to output the ul list.

  • Thanks for your help, I'm not very good with php, can you modify my code? Dec 25, 2014 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.