The Loop
-
The loop is still a little high-concept for me, so forgive me if I’m stupid here. But in my header.php, I’m trying to display a featured image in the header, if it’s set. So I’m using something along the lines of
<?php if ( has_post_thumbnail() ) { the_post_thumbnail(); } else { ?> <p>No thumbnail</p> <php } ?>
This works great on all of my pages. But on the archives, things get a little fuzzy. In my mind, that code should return “No thumbnail” on the archive pages. But it doesn’t. It returns the thumbnail of the last-grabbed post on the page. I know that this has something to do with the loop, I just don’t know the best way to fix it.
I do realize that functionally, I could fix my problem by just wrapping that with
if (!is_archive())
and then setting a rule for archive pages separately, but is that the best solution? I’m trying to wrap my head around the loop and understand why this happens in the first place, and figure out if there’s a better solution to stop it.
- The topic ‘The Loop’ is closed to new replies.