Updating Custom Field Thumbnail for Revolution Theme Automatically

by Kishore on January 17, 2009

thumbnail-wordpress

If you are using any theme like Revolution Themes for Wordpress  which needs to use thumbnail image information in custom field, you can understand that you need to update the image details after you upload the image. I use windows live writer to post on my blogs and its bugging for me to always save the posts as draft and then update the thumbnail custom field. I am using an hack where I never bother about updating the thumbnail values. Calling this function when the page loads for the first time updates the thumbnail meta_post value which can be updated using add_post_meta function.

You can add this function to your functions.php file in your theme folder.

function getThumbnailURL($postId) { if( get_post_meta($postId, "thumbnail", true) ) { } else { $images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $postId ); if($images) { $firstImageSrc = wp_get_attachment_image_src(array_shift(array_keys($images))); if(strlen($firstImageSrc[0])) { add_post_meta($postId, 'thumbnail', $firstImageSrc[0]); } else { $sThumbUrl = "http://www.kisaso.com/wp-content/themes/church_20/images/kishfav-110.png"; add_post_meta($postId, 'thumbnail', $sThumbUrl); } } else { $sThumbUrl = "http://www.kisaso.com/wp-content/themes/church_20/images/kishfav-110.png"; add_post_meta($postId, 'thumbnail', $sThumbUrl); } } }

 

Now inside the loop you can call this function

<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php getThumbnailURL($post->ID); ?>

Before you do this make sure that you have set the thumbnail size in the Media settings. I am using this hack on this blog

Possibly Interesting Posts

Wordpress MU 2.9.1.1 Upgrade Error : Yesterday I upgraded my Wordpress MU installation to version 2.9.1.1 which has some fixes that I had..[](0)
5 Hacks that Will Challenge Obama's Cyber-Security Plans : President Barack Obama has made cyber-security a priority since he took office in January. A month ..[](1)
Freshen Your Fridge with Citrus Peels and Salt [Food Hacks] : We all know about keeping a box of baking soda in the fridge, but the TipNut blog suggests a citru..[](1)
Rubina dad unhappy with govt home : AGE CORRESPONDENT Mumbai May 30: Slumdog Millionaire child-actor Rubina’s father Rafiq Quereshi ..[](0)
Rejected by Apple, Palm teams with Amazon : You know the foolish game of cat and mouse Palm has been playing with Apple? The one where Palm hack..[](1)
Fill out your e-mail address to receive our free newsletter from Kishore Blog!
E-mail address:
Name:
 

{ 2 trackbacks }

11 ways to customize your Wordpress blog to your needs
February 19, 2009 at 9:06 am
Advantages of Magazine Style Theme
October 5, 2009 at 3:37 pm

{ 51 comments… read them below or add one }

sweet January 25, 2009 at 12:23 pm

can you pls explain the usage of this hack clearly?

Reply

Kishore January 25, 2009 at 1:00 pm

can you please tell me where you are stuck, just add the above function to the functions.php file inside the template folder(the enabled template) and call the function as shown below inside the loop where you want to generate the thumbnails

Reply

Wins January 27, 2009 at 5:21 am

Hi, I’m newbie in WP, and I try to using Revo Chruch, can I ask you?
1. As I know Revolution is free, can I use it for long time?, I mean any trial period in revolution like software?

2. I still dont undrstand about thumbnail, pic in future content, etc.. You can looks my blog, there is no picture in my blog. How I build it?

3. How to drop vidoes in futured content like this web?

4. can you explain me step by step and send to my mail. many thanks..

Thanks for your attention, And I hope my blog will be better like your website.
Greeting from Indonesia

Reply

Kishore January 27, 2009 at 9:56 am

1. I don’t think Revolution Church is free
2. I saw your blog, you need to do some posts and assign the category to the blocks on your front page
3. Update the Revolution theme settings, like the video code
Porting or making changes like the things I have done, will need some knowledge in wordpress coding and PHP.
Information related future posts can be found here http://www.kisaso.com/display-upcoming-posts-on-your-sidebar-wordpress-blogs/
You need to update the thumbnail url in the custom field when you do the post and for featured content, you need create a category called Featured and assign the meta custom field with the url of the image.

Reply

David February 15, 2009 at 10:59 pm

where exactly do I need to add the code above? I know I have to add it in functions.php but where? at the beginning, in the middle? I am new with this template and I have no idea how to fix my thumbnails. I do appreciate your help. Thank you so much in advance

Reply

Kishore February 16, 2009 at 12:41 am

You can add the function anywhere you like into the functions.php file and call it at the homepage.php inside the loop

Reply

David February 17, 2009 at 6:28 am

Hey Kishore! Thank you for being so patient and helpful. Could you please explain me the part when you say: call it at the homepage.php inside the loop. I am sorry for so many questions, I’m still new with all these blogs and themes… Thank you so for your cooperation

Reply

Kishore February 17, 2009 at 9:45 am

David – First you need to call the function in the single.php or the index.php file in case of revolution theme

< ? php if (have_posts()) : while (have_posts()) : the_post(); ?>
< ? php getThumbnailURL($post->ID); ?>

The above code will add the thumbnail custom field if its not added and if its already added, nothing will be done

Then you can display the thumbnail on your homepage or where ever you want to display

Reply

David February 18, 2009 at 2:12 am

Hi Kishore! I’m sorry to bother you again, but I don’t know what I’m doing wrong. Could you please give a help? here is my functions.php

I would like you to check my blog, but I haven’t publish it yet. Im running wordpress locally. Thank you so much for all your help and I’m sorry for asking so many questions. Thanks

Marc @ NoRecipes February 16, 2009 at 1:40 pm

Hi Kishore, I’m trying to add thumbnails to the Similar Posts plugin I use. According to the authors website I can add thumbnails by creating a custom field for each post with the thumbnail URL. Since I already have over 200 posts, I was hoping to find an automated way of grabbing the thumbnail of the first image in the post. I think that’s what your function is supposed to do?

I’ve added it to functions.php and am calling it at the top of my post template as follows: . I’ve tried loading a couple pages and checking the custom fields from the admin interface, but I do not see any new custom fields for these posts.

Any idea what I’m doing wrong? Thanks!

Reply

Kishore February 16, 2009 at 3:58 pm

Marc – You should call the function inside the loop and not on the top of the page.

Reply

Marc @ NoRecipes February 16, 2009 at 9:01 pm

Thanks Kishore, I also had the post ID parameter wrong in the call to the function. Fixed now and working! One quick question, if I decide that the current thumbnail size is too big, can I change it in the media settings and have it update “thumbnails” or does it only work the first time it’s run? Thanks!

Reply

Kishore February 16, 2009 at 9:14 pm

Marc – the thumbnails are already saved with the settings when you upload the image, so you cannot change the size of the already created thumbnails, but I can suggest a solution for you. Set the image size in the style.css file for the class you use. Suppose your style name is article and the size you need is 70×70px, just add this
.article img {
widht:70px;
height:70px;
}
I have done this and its working for me

Reply

Marc @ NoRecipes February 16, 2009 at 10:55 pm

Great idea! Thanks so much for the help!

Marc @ NoRecipes February 17, 2009 at 2:12 am

It was all working so well, but I’ve found a problem. When I go into create a new post, there are hundreds of instances of the custom field “thumbnail” prepopulated in the new post. There are so many instances, it’s preventing the add new post from fulling loading.

I’ve added your function exactly as you have it shown above with the exception of the “no-image” url. I’ve added the call inside the loop of my post page as follows:

?php getThumbnailURL($post->ID);

Any ideas what might be going wrong? Thanks

Reply

Marc @ NoRecipes February 17, 2009 at 2:36 am

I guess I actually have 2 questions. First, I need to clean up my DB because I now have 1474 keys called “thumbnail” in the wp_postmeta table. I’d like to get purge all custom field keys and values and just start over.

Also, wondering if there’s some way to prevent the function from generating a custom field every time a post is loaded so this doesn’t happen again?

Thanks!

Reply

Marc @ NoRecipes February 17, 2009 at 2:50 am

Hi, it’s me again, sorry for all the comments, but I’ve figured out how to delete all the “thumbnail” records from the database, so my first question is answered. I’d really like to get the auto thumbnail to custom field thing working though, so would appreciate if you could share ideas on how I can prevent it from continuing to add custom fields every time the page is loaded that would be great. Thanks!

Reply

Kishore February 17, 2009 at 9:39 am

Marc – There were 100’s of instance of thumbnail because you had earlier placed the function outside the loop. If its placed correctly, it will create only one custom field for every post.

Reply

David March 9, 2009 at 2:24 am

Kishore,

I need your help.. I am using Revolution Church theme.. what is happening is the Featured Cat #1 and Cat #2 and also the Bottom Featured Category are all the same. How can I change this so each post will be different.. take a look at my test site… http://www.danjex.com/new/

Thanks/ David

Reply

Kishore March 9, 2009 at 2:13 pm

David, You need to edit the home.php file and assign the right category Id to display the posts correctly.

Reply

David March 9, 2009 at 7:43 pm

Dear Kishore,

Thanks for your reply. I have followed what you suggested.. This is what I did..

These are my posts ID’s

Test ID 7
Links ID 5
Lorem ID 3

This is what my Home.php looks like..before any changes..( homepageleft)

have_posts()) : $recent->the_post();?>
ID, “thumbnail”, true) ): ?>

Cat=1 has been changed to Cat=7 ( taken from Test ID = 7 ) this is what I get.. See website…www.danjex.com/new

The hompepageleft is no longer there..

Looking forward to your suggestions.

Thanks David

Reply

Kishore March 9, 2009 at 9:51 pm

David I think you have missed something. Need to check your code, can you email me your home.php in a text file

Reply

DC April 7, 2009 at 6:38 pm

Hi,

I just started trying using Wp revolution.
I managed to get the featured content part working but I am not sure how to get the thumbnail sections going.
I have added the custom fields “thumbnailimg” and “featuredtext” text but they just do not appear.
Please help with some advice.

Thank you v much in adv

Reply

Kishore April 7, 2009 at 9:59 pm

Daniel, is the custom image name thumbnail or thumbnailimg, please check that

Reply

DC April 10, 2009 at 12:09 pm

Thank you for the tip Kishore.
Amazing how I got that wrong.

I have got another problem on hand.
My Featured Content Gallery seems to appear on every page.
That is if I click on the thumbnails article, the Featured Content Gallery still appears at the top of that article..

Thanks in Adv

Reply

tech-plazaa April 23, 2009 at 8:07 pm

hey bro can you tell me how i can change the size fo thumbanin in revolution theme please replay soon

Reply

Kishore April 23, 2009 at 9:02 pm

change your Media setting, you can set the thumbnail size of your images there (Wordpress Dashboard Settings)

Reply

tech-plazaa April 24, 2009 at 10:03 am

hey bro i am not talking about the thumb in post . iwant to know that how ican change the size of the thumbnail of revolution theme front page
actually i have a revolution magzine premium theme but i want to change the size of thumbnail which is shown on its front page
you can see the example here
http://www.firsttry.0fees.net (i uploded it temp)
here you will be see on the right side the small thumb of image i want to change there size please help me brother

Reply

Kishore April 28, 2009 at 11:43 am

tech-plazza – you can set the size of the thumbnail in the media settings in your admin dash board

Reply

MC April 27, 2009 at 10:57 am

Kishore

I have tried your instructions as mentioned above but still im getting no good results.

1. Am I supposed to include the end of the if and while for this function call in the index.php?

i.e.
ID); ?>

2. Is there an specific order to put the script in the function.php file?

3. Could you share some screens shoots of your function and index file or may be email me?

Thanks in advanced!

MC

Reply

Kishore April 28, 2009 at 11:41 am

MC – you can add the function to your functions.php file in the theme anywhere. You need to call the function inside the loop in the home.php file like you see the code above inside the loop

Reply

MC April 28, 2009 at 10:18 pm

Kishore to be honest this isnt working.

I have tried everything. Do you mind if you take a look @ my code so you can tell me what im doing wrong?

This is my home.php file code:

( where inside the loop im supposed to put the code you mention above?)

ID); ?>

home.php

Featured Music

have_posts()) :

$recent->the_post();?>
ID, “hpbottom”, true) ): ?>
<a href=”" rel=”bookmark”><img style=”float:left;margin:0px 10px

0px 0px;” src=”ID, “hpbottom”, true); ?>” alt=”" />

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px

10px 0px 0px;” src=”/images/thumbnail.png” alt=”" />

<a href=”" rel=”bookmark”>

Read More

Posts From This Category

Our Ministries

have_posts()) : $recent->the_post();?>

ID, “thumbnail”, true) ): ?>

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px 10px 0px 0px;” src=”ID, “thumbnail”, true); ?>” alt=”" />

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px

10px 0px 0px;” src=”/images/thumbnail.png” alt=”" />

<a href=”" rel=”bookmark”>

Read

More Posts From This Category

Serving Opportunities

have_posts()) :

$recent->the_post();?>
ID, “thumbnail”, true) ): ?>
<a href=”" rel=”bookmark”><img style=”float:left;margin:0px 10px

0px 0px;” src=”ID, “thumbnail”, true); ?>” alt=”" />

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px

10px 0px 0px;” src=”/images/thumbnail.png” alt=”" />

<a href=”" rel=”bookmark”>

Read More Posts From This Category

Reply

MC April 28, 2009 at 10:24 pm

FYI: im using revolution church

Reply

Kishore April 28, 2009 at 11:14 pm

Can you please show me the link to your blog.

MC April 28, 2009 at 11:50 pm

My link is www dot moisescolon dot com

Reply

Kishore April 29, 2009 at 8:02 pm

MC – I saw your blog, but there are no images on your posts, so its showing the replacement image

Reply

MC April 29, 2009 at 8:53 pm

Kishore – Thanks for visiting my blog but there will be no images on my post because im still trying to figure out WHERE to put the call of the function on the home.php. That’s why i sent you an email with my files so you can show me exactly or may be do it by yourself.

I will post the piece of code here if it works for the help of everyone. I guess everyone is having the same issue and not having the explanation clear. May be because we are not so geeky, at least, that’s my case.

Sorry for bother you a lot but im still have no good results with the little explanation in this post.

Valentin Yonte April 28, 2009 at 4:45 am

Hi all,
I try to understand how this code work. In some messages comment about to put one code on home.php, in other one, you say to put it on index.php, inside a loop?

In what file really we need tu put this conde, on home. or on index.

Another question is about the loop. I don’t know where you want to say with this, in what part of the code, we need to put it.

Greetings
Valentin Yonte

Reply

Kishore April 28, 2009 at 11:42 am

Yonte – You need to call the function inside the loop in your home.php file as the thumbnails are displayed on the home page

Reply

Valentin Yonte April 30, 2009 at 6:35 pm

Hi Kishore, I try to do that you comments, even, I talk with Moises, but I don´t get good result that you can see on my blog
http://www.activosenred.com.

Could you help me to solve the problem?
Thank´s

Reply

Kishore May 1, 2009 at 7:07 am

Valetin, your image sizes can be set using a css style for the thumbnail

Reply

Moises April 28, 2009 at 4:59 am

Im wondering why my comment isnt appear anymore?

Reply

Kishore April 30, 2009 at 12:07 am

MC – I have emailed you the files with changes. Hope it works well for you

Reply

MC April 30, 2009 at 8:36 am

Kishore – thanks for your help! Everything is working great now!

For the rest of the people here let me explain. Im using rev church

I was putting the function in the functions.php file the right way as mentioned here.

also i was calling the function the right way in the home.php as mentioned here

but… at least with rev church i was taking the div id homepagebottom and putting it right after the div id homepagetop… for some reason that gave me an error.

Now that everything is as the original code is working!

thanks for the help kishore!

PD

im just wondering two things:

1. the same process will work for the revolution magazine theme..
2. How can i implement a footer like yours? Is that a plugin or widget?

Reply

Kishore April 30, 2009 at 12:01 pm

Thanks MC, The footer is custom coding, its not a plugin or widget. Yes you can use it for revolution magazine too

Reply

Leftha May 26, 2009 at 10:30 am

Hey Kishore! I try to understand , you say to put it on home.php, inside a loop?

This is my home.php,where exactly do I need to add the code above? I do appreciate your help. Thank you so much in advance

Nacionales

have_posts()) :

$recent->the_post();?>

ID, “thumbnail”, true) ): ?>

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px 10px 0px 0px;”

src=”ID, “thumbnail”, true); ?>” alt=”" />

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px 10px 0px 0px;”

src=”/images/thumbnail1.png” alt=”" />

<a href=”" rel=”bookmark”>

Leer más noticias en esta categoría

Internacionales

have_posts()) :

$recent->the_post();?>

ID, “thumbnail”, true) ): ?>

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px

10px 0px 0px;” src=”ID, “thumbnail”, true); ?>” alt=”" />

<a href=”" rel=”bookmark”><img

style=”float:left;margin:0px 10px 0px 0px;” src=”/images/thumbnail.png” alt=”" />

<a href=”" rel=”bookmark”>

Leer más noticias en esta categoría

Política

have_posts()) :

$recent->the_post();?>

ID, “hpbottom”, true) ): ?>

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px

10px 0px 0px;” src=”ID, “hpbottom”, true); ?>” alt=”" />

<a href=”" rel=”bookmark”><img

style=”float:left;margin:0px 10px 0px 0px;” src=”/images/thumbnail.png” alt=”" />

<a href=”" rel=”bookmark”>

Leer más noticias en esta categoría

Reply

Leftha May 26, 2009 at 10:33 am

Sorry, this is my home.php

Nacionales

have_posts()) :

$recent->the_post();?>

ID, “thumbnail”, true) ): ?>

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px 10px 0px 0px;”

src=”ID, “thumbnail”, true); ?>” alt=”" />

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px 10px 0px 0px;”

src=”/images/thumbnail1.png” alt=”" />

<a href=”" rel=”bookmark”>

Leer más noticias en esta categoría

Internacionales

have_posts()) :

$recent->the_post();?>

ID, “thumbnail”, true) ): ?>

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px

10px 0px 0px;” src=”ID, “thumbnail”, true); ?>” alt=”" />

<a href=”" rel=”bookmark”><img

style=”float:left;margin:0px 10px 0px 0px;” src=”/images/thumbnail.png” alt=”" />

<a href=”" rel=”bookmark”>

Leer más noticias en esta categoría

Política

have_posts()) :

$recent->the_post();?>

ID, “hpbottom”, true) ): ?>

<a href=”" rel=”bookmark”><img style=”float:left;margin:0px

10px 0px 0px;” src=”ID, “hpbottom”, true); ?>” alt=”" />

<a href=”" rel=”bookmark”><img

style=”float:left;margin:0px 10px 0px 0px;” src=”/images/thumbnail.png” alt=”" />

<a href=”" rel=”bookmark”>

Leer más noticias en esta categoría

Reply

Kishore May 26, 2009 at 5:01 pm

You should call this function after all the
have_posts()) :

Reply

Leftha May 27, 2009 at 12:11 am

The “error” keeps appearing, and this is the message i read ( Parse error: syntax error, unexpected ‘<’ in /home/javierar/public_html/Altavoz/wp-content/themes/church_20/home.php on line 81)

Please, could you tell me by e-mail what is wrong with that? or what am i doing wrong? I can send you my home.php. Thank you in advance.

Reply

deepak February 13, 2010 at 1:51 pm

hi kishore
i have applied your method but this does not work for me. can u send me updated file (functions.php, home.php & single.php)
thanks
deepak

Reply

Kishore February 18, 2009 at 2:10 pm

David, I checked your code, just add the function on top of the file inside the php tag. then call it inside the loop of the single.php. I have explained it above

Reply

Leave a Comment

Previous post:

Next post: