Latest Image Thumbnail On Arthemia

Hi again!

Yesterday, my friend Lester from Australia asking me about the legendary theme from ColorLabs, Arthemia.

If you check the theme dashboard (thumbnail settings), you will find an option like picuture below:

Capture

 

From that description, i thought that i can displaying the first image uploaded to my post. But, the fact is not like that. The post thumbnail that displayed on this site is not the first, but the latest. So, i can say if this option is not 100% work, since the automatic thumbnail is working fine (if you don’t have any featured image, it will take the uploaded image to your post).

And that is what Lester asked to me. To fix this problem, you can change the output of the function. For example, you can open a file named index.php. Find out this code:

<?php
		$latest_thumb=get_option('colabs_latest_post_thumb');
		if($latest_thumb!='No'){
		$width = get_option ( "colabs_thumbWidth_LatestPost" );
		$height = get_option ( "colabs_thumbHeight_LatestPost" );
		if ( $width == 0 ) { $width = 150; }
		if ( $height == 0 ) { $height = 150; }
				colabs_pp('width='.$width.'&height='.$height.'&size=medium-thumb&play=true&wrapper_class=left&link=img');
		}
	?>

Edit that code become:

<?php
    global $post;
    $args = array( 'post_type' => 'attachment', 'order' => 'ASC','numberposts' => 1, 'post_mime_type' => 'image', 'post_status' => null, 'post_parent' => $post->ID ); 
    $attachments = get_posts($args);
    if ($attachments) {
            foreach ( $attachments as $attachment ) {
                    // Method #1: Allows you to define the image size
                    $src = wp_get_attachment_image_src( $attachment->ID, "attached-image");
                    if ($src) { 
											
											$latest_thumb=get_option('colabs_latest_post_thumb');
											if($latest_thumb!='No'){
											$width = get_option ( "colabs_thumbWidth_LatestPost" );
											$height = get_option ( "colabs_thumbHeight_LatestPost" );
											if ( $width == 0 ) { $width = 150; }
											if ( $height == 0 ) { $height = 150; }
													colabs_pp('width='.$width.'&height='.$height.'&size=medium-thumb&play=true&wrapper_class=left&link=img&src='.$src[0]);
											}
										}

            }
    }
	?>

At the new code, if you take a look you will find a new logic to find the array of the images. Since we cannot determine how many images uploaded into the post, then we are using a sort to determine the first image.

By default if you are not using the sort (on this case i’m using order on the loop) the result is the same as what as the default colabs_pp function output. By using the sort to ordering the post, you can easily take the first image uploaded.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s