3 Ways to Generate Thumbnails in Thesis Theme without Plugin

This tutorial is exclusively for Thesis Framework, a new templating system for WordPress. Create any sort of layout for your website using Drag & Drop Builder.

Share This Article:

3 Ways to Generate Thumbnails in Thesis Theme without Plugin. Thumbnails in excerpts can be displayed using different ways, that too without using a single plugin. All the methods listed below are tested well and works fine on latest version of Thesis.

We have made a through research on all possible ways to generate and display thumbnails in thesis wherever we need. Finally, we found these code snippets useful and using the same you can display thumbnails in recent posts, popular posts etc. Now, lets move to the coding part.

generate-thumbnails-thesis-theme-without-plugin

You need to Get Thesis Theme to perform these experiments. Also, dont forget to backup your theme, sometimes you may end-up breaking code in it.

1. Generate Thumbnails from Thesis Custom Post Image Values

This is the default method through which thumbnails can be displayed in teasers on home and archive pages.

thesis-post-thumbnail-options

Function of the Code:

Here is an example of the code, that can be used in any part of thesis theme to generate thumbnail for that particular post based on the custom post image values. This code can also be used in a loop and helps to create related posts with thumbnails in thesis theme.

<a href="<?php the_permalink() ?>" rel="bookmark">
<img src="<?php bloginfo('template_url'); ?>/lib/scripts/thumb.php?src=/<?php $values = get_post_custom_values("thesis_post_image"); echo $values[0]; ?>&amp;w=150&amp;h=150&amp;zc=1" alt="<?php the_title(); ?>" />
</a>

You can change the width and height values by tweaking the highlighted part in the code. If you using Thesis for a long time, then this is the best method. Include this code in the functions and display it in a teaser using thesis hook.

Read Add Author Bio Box below single post in Thesis

2. Automatically Generate Thumbnail from First Image

Here is an excellent code that automatically generates thumbnail from first image in the post. All you need to do is include the below code in custom_functions.php file.

/** Catch First mage in the post and display it */
function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){
$first_img = "default.png"; /** Define a Default Image */
}
return $first_img;
}

Function of the Code:

Use this method only, if you dont have pre-defined thesis custom post images. Add this code wherever you need thumbnail, it will check for first image in the post and display it based on the width, height values mentioned in the code. If there are no images, then it will display a default one.

<a href="<?php the_permalink() ?>" rel="bookmark">
<img src="<?php bloginfo('template_url'); ?>/lib/scripts/thumb.php?src=/<?php echo catch_that_image() ?>&amp;w=150&amp;h=150&amp;zc=1" alt="<?php the_title(); ?>" />
</a>

If there in no image in the post and if no default image is defined, then it wont display anything. So, try to provide atleast one option, for better functioning of code.

Check Add Breadcrumbs in Thesis Theme Without Plugin

3. Generate Thumbnail from Featured Image

Here is another awesome method to automatically generate thumbnails in thesis theme. First of all, you need to add “post thumbnails” support to thesis theme. Add below code to custom_functions.php file and save it.

/** Add featured Image Support in Thesis */
add_theme_support('post-thumbnails');
set_post_thumbnail_size( 150, 150, true );
add_image_size( 'single-post-thumbnail', 600, 400 );

This is the most popular method used on every WordPress theme. After adding support for “featured image” in WordPress thumbnails, then a link “Use as featured image” will be displayed for every image. You need to select one image as the featured image for that particular article, by clicking on this link.

wordpress-thumbnail-support
Function of the Code:

Now, this code will help to fetch the featured image and will display it as the thumbnail. So, for the working of this, every post must have a featured image.

<a href="<?php the_permalink() ?>" rel="bookmark">
<?php the_post_thumbnail(array( 150,150 ), array( 'class' => 'imgfeat', 'alt' => the_title('', '', FALSE), 'title' => the_title('', '', FALSE) )); ?>
</a>

OR

<a href="<?php the_permalink() ?>" rel="bookmark">
<img src="<?php bloginfo('template_url'); ?>/lib/scripts/thumb.php?src=/<?php echo the_post_thumbnail() ?>&amp;w=150&amp;h=150&amp;zc=1" alt="<?php the_title(); ?>" />
</a>

Both these methods are same and use them based on the requirement. There is also flexibility to change the size of thumbnails in both the cases. So try both of them and stick to the one which works perfect for you.

Display Thumbnails in Teasers of Thesis Theme

Now you can use code from any of these methods to display thumbnails in teasers of your thesis theme. Here is the simple function for that

/** Start of Display Thumbnails in Teasers of Thesis Theme */
function teaser_thumbnails() {
if (is_home()) { ?>
<div id="teaser-thumbnails">

</div> <?php } } add_action('thesis_hook_before_teaser', 'teaser_thumbnails'); /** End of Display Thumbnails in Teasers of Thesis Theme */

Now, insert any of the 3 codes (based on the method you are using to generate thumbnails) between <div id="teaser-thumbnails"> and </div> tags. Add the complete code in custom_functions.php file and voila thumbnails will be live on your home page.

Some CSS to make those thumbnails float left

Add below CSS code to custom.css file and save it.

#teaser-thumbnails {
float: left;
margin: 0 10px 10px 0;
}

Hope you like these methods to generate thumbnails in thesis theme without the use of any plugin. If you need any help regarding this, drop a comment here.

This tutorial is exclusively for Thesis Framework, a new templating system for WordPress. Create any sort of layout for your website using Drag & Drop Builder.

Genesis is the most flexible WordPress theme framework that comes with tons of options. We have been using Genesis on all of our blogs and recommending the same to you. Every bit of it is coded according to the standards. Give it a try!

Comments

  1. Dilawer Pirzada says:

    I don’t Use Thesis Framework, I’m using Genesis Framework.
    Would you like to reveal the secret about Thesis and Genesis, which one is better!
    I don’t think that Thesis would be better. Please, distinguish BTW here in comment?

  2. Kulwant Nagi says:

    Thanks for sharing these easy to do steps !!

  3. Sai Krishna says:

    Bro I’m confused on the 2nd way 2nd step. We have to add that function code in every post manually ?

    • kacia says:

      Yes! wondering the same! Thanks!!

Speak Your MindComments Policy →

*

Looking for More Awesomeness?

Read previous post:
add-second-navigation-menu-thesis
How to Add Second Navigation Menu in Thesis Theme

How to Add Second Navigation Menu in Thesis Theme by using WordPress menu support. Thesis Theme comes with a primary...

Close