Visually, what I'm looking for is this: grid layout

So somehow I need to pull the date and each featured image from the years they were posted. I am in the wordpress loop.

I've looked around but couldn't find anything that I could get to work. I'm basically a php noob so be gentle!

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
                    <p style="background-image: url('<?php echo wp_get_attachment_url( get_post_thumbnail_id( $post->ID ) ); ?>"><a href="<?php the_permalink(); ?>" title="<?php echo the_title(); ?>">&nbsp;</a></p>
                <?php endwhile; else : ?>

Obviously this isn't working. I'm not even interacting with the database here. At first I wanted to put up all post thumbs in one grid without the year. But that might become too overwhelming.

  • 1
    This question is too broad to answer in a Q&A-model. What have you done so far to achieve this? Where are you stuck?
    – cjbj
    Commented Jan 11, 2018 at 11:07
  • cjbj, I edited the post to reflect my feeble attempt. I know I need to grab the posts by year, then extract post thumbs but I have no idea how to query the database in such a way that would work. Commented Jan 11, 2018 at 14:17
  • Just to be clear, do you want to list all images that are being used as post thumbnails, or do you want to list all posts and their post thumbnails?
    – swissspidy
    Commented Jan 17, 2018 at 13:13
  • It was just featured images from all posts. I'm a photographer, so the emphasis on my archive were the photos. People may identify the photograph before the text content. It was important to make that happen. Did you see the working example? Commented Jan 21, 2018 at 12:33

1 Answer 1


The only way to build what I did was to use different WP_Queries. I ran in to a few issues because I wanted to use the same layout for viewing categories. I know this isn't much of an answer so I did sign up on the github network and post a gist of it: full code

And here's what I wanted to end up with at my website

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