Wordpress Themes - WP Forum at BFA
There will be no more development for Atahualpa (or any other theme), and no support. Also no new registrations. I turned off the donation system. I may turn the forum to read only if it gets abused for spam. Unfortunately I have no time for the forum or the themes. Thanks a lot to the people who helped in all these years, especially Larry and of course: Paul. Take care and stay healthy -- Flynn, Atahualpa developer, Sep 2021

Wordpress Themes - WP Forum at BFA » WordPress Themes » Atahualpa 3 Wordpress theme »

[SOLVED] Help using the_post_thumbnail


  #1  
Old Jan 16, 2011, 07:46 AM
Tim F
 
66 posts · Jul 2009
Hi all,

I am trying to set up a bit of code to show the latest post excerpt from a particular category. I want the post thumbnail to display if it is present in that post, and if not I want a default image to show. I am using this:

Code:
<?php global $post;
$myposts = get_posts('numberposts=1&category=8');
foreach($myposts as $post) :
?>
<a href="<?php the_permalink(); ?>">
<?php if (has_post_thumbnail()) the_post_thumbnail( array(100,100) ); else echo '<img class="social" src="default.jpg" alt="No Thumbnail" title="No Thumbnail" />';
?><br>
<?php the_title(); ?></a>
<?php endforeach; ?>
I can't get it to load the post thumbnail and I am wondering - am I wrong in assuming that the 'set featured image' box in the post is supposed to be the thumbnail? Or should I be choosing the thumbnail somewhere else? Or is my code just borked?
  #2  
Old Jan 16, 2011, 10:57 AM
lmilesw's Avatar
lmilesw
 
10,176 posts · Jul 2009
Central New York State USA
I'm not sure where you are placing that code but I would use the List Category Posts Plugin for what you are trying to do and the Feaured Image function works fine.
__________________
~Larry (CNY Web Designs)
This site should be a membership site since it so full of good stuff.
Please consider donating which gives you access to even more good stuff.
  #3  
Old Jan 17, 2011, 06:20 AM
Tim F
 
66 posts · Jul 2009
I am putting this in style and edit center column. I was hoping I could achieve it without using any more plugins as my site is starting to get a bit bloated with them.

So it sounds like featured image is what I need to choose the thumbnail, so there must be a problem with my code. I wonder if I actually need to specify which post has the thumbnail in my if statement? But that would make the whole thing pretty redundant.
  #4  
Old Jan 17, 2011, 06:51 AM
Tim F
 
66 posts · Jul 2009
Solved - I needed to add this: setup_postdata($post);

So the whole thing now reads

Code:
<?php global $post;
$myposts = get_posts('numberposts=1&category=13');
foreach($myposts as $post) :
setup_postdata($post);
?>
<a href="<?php the_permalink(); ?>">
<?php if ( has_post_thumbnail() ) the_post_thumbnail( array(100,100) ); else echo '<img border=0 class="social" src="defaultimage.jpg" alt="No Thumbnail" title="Example" />';
?><br>
<?php the_title(); ?></a>
<?php endforeach; ?>
And when added to 'style and edit center column' it shows the latest post title from category 13 and the thumbnail if there is one, or a default image if not. I set up multiple instances in a table to show posts from several of my categories on the home page.

Bookmarks



Similar Threads
Thread Thread Starter Forum Replies Last Post
Call to undefined function the_post_thumbnail() anatta Page & Category Menu Bars 3 Jan 23, 2010 09:47 AM
Call to undefined function the_post_thumbnail() numone Header configuration & styling 5 Jan 20, 2010 07:45 PM
[SOLVED] Excerpt Error: &quot;Fatal error: Call to undefined function: the_post_thumbnail( buzz628 Excerpts, Read more, Pagination 2 Jan 15, 2010 03:58 PM


All times are GMT -6. The time now is 12:26 PM.


Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.