Here’s the code in pastebin (thanks, Michael)
https://pastebin.com/K7EYxQjS
Yup, you misplaced the loop code. Your thumbnail output code only works on the initial first pass and the loop code actually loops, but does nothing because there is no code within the loop. Try modifying the related portion of your template as follows. Any code before or after what’s shown remains the same.
<p>
These are the posts filed under the <?php single_cat_title(); ?> category. You will not be able
to identify the post content other than the photograph that associates with the post. I've
decided that adding text to each photo would just be too much.
</p>
</div>
<?php while ( have_posts() ) : the_post(); ?>
<div class="archive-gallery">
<?php if ( has_post_thumbnail() ) : ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" ><?php the_post_thumbnail(); ?></a>
<?php endif; ?>
</div>
<?php endwhile; ?>
</div>
</main>
<?php else :
esc_html_e( "Sorry. No posts match your criteria." );
All I did was move the while and endwhile lines, coordinating the <?php ?> tags as needed.
Hi BC! Long time no see. Thanks for your expertise, bud. I’ll give what you added a shot in a bit. A comment, though… I didn’t know you could nest a loop inside of a loop? Is that what I’m seeing?
-
This reply was modified 8 years, 7 months ago by
harshclimate.
try and move the output of the featured image into the loop;
example https://pastebin.com/nVvQdm3R
I am not sure about your intended html structure, so you might need to adjust the location of the html tags in the code.
I’m sorry I didn’t recognize you at first, it has been a long time! I’m glad your topic is not being ignored this time 🙂
Sure, you can nest loops, but it can get confusing with nesting the while(): endwhile; syntax. It’s best to keep that to one instance (I prefer the outermost instance) and use the while() {} syntax for the inner loops. I don’t see where we’re nesting loops here, but I’ve been known to suffer from selective blindness when it comes to seeing significant code elements 🙂
Do ensure loops are fully nested and not overlapping. Don’t do this:
while ( condition_a()):
while ( condition_b()) {
do_something();
// the final } belongs here
endwhile;
}
What you cannot nest is <?php ?> tags. Doing so is illogical, but it can happen with novices or the more experienced not paying attention. PHP throws a syntax error when you try, so it doesn’t get very far.