![]()
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


{ 2 trackbacks }
{ 51 comments… read them below or add one }
can you pls explain the usage of this hack clearly?
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
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
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.
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
You can add the function anywhere you like into the functions.php file and call it at the homepage.php inside the loop
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
David – First you need to call the function in the single.php or the index.php file in case of revolution theme
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
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
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!
Marc – You should call the function inside the loop and not on the top of the page.
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!
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
Great idea! Thanks so much for the help!
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
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!
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!
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.
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
David, You need to edit the home.php file and assign the right category Id to display the posts correctly.
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
David I think you have missed something. Need to check your code, can you email me your home.php in a text file
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
Daniel, is the custom image name thumbnail or thumbnailimg, please check that
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
hey bro can you tell me how i can change the size fo thumbanin in revolution theme please replay soon
change your Media setting, you can set the thumbnail size of your images there (Wordpress Dashboard Settings)
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
tech-plazza – you can set the size of the thumbnail in the media settings in your admin dash board
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
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
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
FYI: im using revolution church
Can you please show me the link to your blog.
My link is www dot moisescolon dot com
MC – I saw your blog, but there are no images on your posts, so its showing the replacement image
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.
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
Yonte – You need to call the function inside the loop in your home.php file as the thumbnails are displayed on the home page
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
Valetin, your image sizes can be set using a css style for the thumbnail
Im wondering why my comment isnt appear anymore?
MC – I have emailed you the files with changes. Hope it works well for you
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?
Thanks MC, The footer is custom coding, its not a plugin or widget. Yes you can use it for revolution magazine too
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
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
You should call this function after all the
have_posts()) :
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.
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
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