Title: Conditional code help need! &#8211; 2 thumbnails showing
Last modified: August 19, 2016

---

# Conditional code help need! – 2 thumbnails showing

 *  [pharmtek](https://wordpress.org/support/users/pharmtek/)
 * (@pharmtek)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/2-thumbnails-showing-conditional-code-needed/)
 * 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 postimage
 * Does that sound right? and if so… what’s the code for that?

Viewing 1 replies (of 1 total)

 *  Thread Starter [pharmtek](https://wordpress.org/support/users/pharmtek/)
 * (@pharmtek)
 * [16 years, 8 months ago](https://wordpress.org/support/topic/2-thumbnails-showing-conditional-code-needed/#post-1241323)
 * Ok, so I solved my problem a round about way…
    Created a post template for the
   posts that need the thumbnail (which are grouped by category).
 * However, if anyone is interested in humoring me about this code, i’d love to 
   see the solution. Thanks!

Viewing 1 replies (of 1 total)

The topic ‘Conditional code help need! – 2 thumbnails showing’ is closed to new 
replies.

## Tags

 * [attachment](https://wordpress.org/support/topic-tag/attachment/)
 * [condition](https://wordpress.org/support/topic-tag/condition/)
 * [custom field](https://wordpress.org/support/topic-tag/custom-field/)
 * [default](https://wordpress.org/support/topic-tag/default/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [thumbnail](https://wordpress.org/support/topic-tag/thumbnail/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 1 participant
 * Last reply from: [pharmtek](https://wordpress.org/support/users/pharmtek/)
 * Last activity: [16 years, 8 months ago](https://wordpress.org/support/topic/2-thumbnails-showing-conditional-code-needed/#post-1241323)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
