Conditional code help need! – 2 thumbnails showing
-
FYI – I think I understand how to fix my problem but am only code at editing existing code and could really use some help writing this fix.
So here’s the problem… I now have 2 thumbnails showing on my single post page… why?
Because I’ve added the following code to my functions.php:
//check attachment function checkimage($size=medium) { if ( $images = get_children(array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => 1, 'post_mime_type' => 'image',))) { foreach( $images as $image ) { $attachmentimage=wp_get_attachment_image( $image->ID, $size ); return $attachmentimage; } } } //get attachment function postimage($size=medium) { if ( $images = get_children(array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => 1, 'order' => 'ASC', 'post_mime_type' => 'image',))) { foreach( $images as $image ) { $attachmentimage=wp_get_attachment_image( $image->ID, $size ); echo $attachmentimage.apply_filters('the_title', $parent->post_title); } } }
With corresponding code in my single.php file to show the image attached to each post:
<?php if(checkimage()) { // if there is an image ?> <?php postimages('medium'); ?> <?php } ?>
(which have been uploaded via the default media gallery)
This all works great except for in the case when I need to use a custom field key to embed a thumbnail (which is necessary for one particular page due to the styling of those posts).
What I need now is some conditional code to fix the problem… I’m thinking it should be something like:
Checkimage
IF there is a thumbnail THEN post thumbnail and END
ELSE postimageDoes that sound right? and if so… what’s the code for that?
- The topic ‘Conditional code help need! – 2 thumbnails showing’ is closed to new replies.