How to do a ‘real’ “has image” check
-
This question is probably for advanced WordPress developers.
I have a dilemma where image thumbnails are being detected as “true” by has_post_thumbnail() even though the image is actually non-existent in the uploads/ folder.
This happens when I use the WordPress importer tool, and the exported process fails to do the: “download post attachments(?)” [paraphrasing].
So say, if you have this generic structure for displaying
the_post_thumbnail()
:if (has_post_thumbnail()) {//this functions checks the database *instead* of the actual presence of the image in the uploads/ folder ?> <a href="<?php the_permalink(); ?>" target="_top" title="<?php the_title(); ?>" rel="bookmark" role="banner"> <?php the_post_thumbnail(); ?> </a> <?php } else { //it's supposed to show a "default" image, but instead, it *blanks* ?> <img src="<?= THE_BLOG_THEME_DIR; ?>/img/fig-<?= rand(1,3); ?>-def.jpg" alt="<?php the_title(); ?>" /> <?php } ?>
Because on the imported data of the post says that the post “has a thumbnail” – the has_post_thumbnail() functions triggers as true – but the image is *not* or is in a wrong directory on the new WordPress installation – the image doesn’t show up.
I’m okay with the image not showing up, but I’d like my conditional to show up with a generic image instead of it triggering a “true” boolean output when it’s supposed to be false.
Somewhere out there, this problem has been worked around – but I’ve been searching and no solutions yet.
There are probably plugins there that fix database-to-image location relationships, but I haven’t seen them yet (recommend please).
Anyone?
- The topic ‘How to do a ‘real’ “has image” check’ is closed to new replies.