Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Post Thumbnails Help WordPress

  • SOLVED

Another simple question with trying to implement the post thumbnail feature on my site.

Currently my code is



<ul class="latestposts"> <!-- Entertainment -->
<?php
global $post;
$postslist = get_posts('showposts=5 && category_name=entertainment');
foreach ($postslist as $post) :
setup_postdata($post);
$image = get_post_meta($post->ID, 'image', $single = true);
?>

<li>

<?php if($image) : ?>
<a href="<?php the_permalink(); ?>"><img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo $image; ?>&amp;w=75&amp;h=50&amp;zc=1" alt="" /></a>
<?php else : ?>
<a href="<?php the_permalink(); ?>"><img src="<?php bloginfo( 'template_url' ); ?>/images/no-image-75x50.jpg" width="75" height="50" alt="" align="left" /></a>
<?php endif ?>
<h3><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>

</li>

<?php endforeach; ?>
</ul>



This currently calls for the "image" custom field and then if no "image" field a random pic that I uploaded to theme will appear to fill the void.

I'm trying to add the post thumbnail feature on my site so that it looks for the thumbnail then "image" field then so on...

I need the thumbnails to be hard cropped, so I added this to my functions.php file.


add_theme_support('post-thumbnails');
set_post_thumbnail_size( 50, 50, true );
add_image_size( 'single-post-thumbnail', 75, 50 ); // Permalink thumbnail size


I then revised my code that's above to include the call to action to the function.php file



<ul class="latestposts"> <!-- Entertainment -->
<?php
global $post;
$postslist = get_posts('showposts=5 && category_name=entertainment');
foreach ($postslist as $post) :
setup_postdata($post);
$image = get_post_meta($post->ID, 'image', $single = true);
?>

<li>

<?php if ( has_post_thumbnail() ) { ?>
<a href="<?php the_permalink(); ?>" title="<?php the_title();?>">
<?php the_post_thumbnail( 'single-post-thumbnail' ); ?></a>

<?php } elseif (get_post_meta($post->ID, 'image', true) ) {?>
<a href="<?php the_permalink(); ?>"><img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo $image; ?>&amp;w=75&amp;h=50&amp;zc=1" alt="" /></a>

<?php else : ?>
<a href="<?php the_permalink(); ?>"><img src="<?php bloginfo( 'template_url' ); ?>/images/no-image-75x50.jpg" width="75" height="50" alt="" align="left" /></a>


<a href="<?php the_permalink();?>" title="<?php the_title();?>">
<img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, 'image', $single = true); ?>&h=65&w=195&zc=1&q=100" alt="<?php the_title(); ?>" class="thumbs-in-archive"/>
</a>

<?php endif ?>
<h3><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>

</li>

<?php endforeach; ?>
</ul>


For some reason it isn't working. Need some assistance please.

Thanks

Answers (1)

2010-06-17

Oleg Butuzov answers:

can you remove this unneed stuff from the script?
$image = get_post_meta($post->ID, 'image', $single = true);


Oleg Butuzov comments:

some times getting post meta values delete the cached postmeta..

has_post_thumbnail is checking for the _thumbnail_id post meta... and its can't found it.


Oleg Butuzov comments:

sample code to check

<ul class="latestposts"> <!-- Entertainment -->

<?php

global $post;

$postslist = get_posts('showposts=5 && category_name=entertainment');

foreach ($postslist as $post) :

setup_postdata($post);

//$image = get_post_meta($post->ID, 'image', $single = true);
$id = $post->ID;
?>



<li>



<?php if ( has_post_thumbnail() ) { ?>

<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>

<?php } elseif (get_post_meta($post->ID, 'image', true) ) {?>

<a href="<?php the_permalink(); ?>"><img src="<?php bloginfo( 'template_directory' ); ?>/timthumb.php?src=<?php echo $image; ?>&amp;w=75&amp;h=50&amp;zc=1" alt="" /></a>



<?php else : ?>

<a href="<?php the_permalink(); ?>"><img src="<?php bloginfo( 'template_url' ); ?>/images/no-image-75x50.jpg" width="75" height="50" alt="" align="left" /></a>





<a href="<?php the_permalink();?>" title="<?php the_title();?>">

<img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo get_post_meta($post->ID, 'image', $single = true); ?>&h=65&w=195&zc=1&q=100" alt="<?php the_title(); ?>" class="thumbs-in-archive"/>

</a>



<?php endif ?>

<h3><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></h3>



</li>



<?php endforeach; ?>

</ul>


Brennen Jones comments:

Thanks,

I tried everything you outlined, but the index.php page is now a blank page.


Oleg Butuzov comments:

can you put your index back. seams code a broken and generate fatal error.

after you dot that you can debug thumbnails by checking a return of the _thumbnail_id post meta

<?php
var_dump(get_post_meta($post->ID, '_thumbnail_id',true));
?>


Brennen Jones comments:

I put my old index.php file back.

Where do I put the code you gave me? The one below:

<?php
var_dump(get_post_meta($post->ID, '_thumbnail_id',true));
?>


Oleg Butuzov comments:

before
<?php if ( has_post_thumbnail() ) { ?>


Brennen Jones comments:

For some reason, it's still not working.

Can I show my entire index.php file and functions.php file for you to assess?


Oleg Butuzov comments:

you can give me ftp credentionals to check to functions code. its will be more fast way...
my mail in my profile.


Brennen Jones comments:

sent


Oleg Butuzov comments:

what the site?i see there at least 5 websites.


Brennen Jones comments:

I'm sorry.

TheUrbanTwist.com site...

WP is installed in the "online" folder.

Thanks