List recent posts but style first result differently?

Here we will discuss about the wordpress general help and support.
  • Ads

List recent posts but style first result differently?

Postby ROY » Thu Aug 05, 2010 1:06 am

Hi, I'm using the following code to return the 6 most recent posts from a set category. What I'd like to do is also a thumbnail image for just the first result. Here's my current code:

<?php $posts = get_posts( "category=4&numberposts=6" ); ?>
<?php if( $posts ) : ?>
<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>

<h3><a href="<?php echo get_permalink($post->ID); ?>" ><?php if (strlen($post->post_title) > 60) {
echo substr(the_title('', '', FALSE), 0, 150) . '';
} else {
the_title();
} ?></a> <span class="date">(</span><a href="<?php echo get_permalink($post->ID); ?>#comments" ><?php comments_number('0', '1', '%'); ?></a><span class="date">)</span></h3>
<?php the_excerpt(); ?>
<?php endforeach; ?>
<?php endif; ?>
Here's the code I've used eleswhere to show the thumbnail image:

<a href="<?php the_permalink(); ?>"><img src="<?php echo get_post_meta($post->ID, "image_preview", true);?>" width="130" height="73" alt="<?php the_title(); ?>" /></a>

But of course if I include it in the first bit of code, they all have a thumbnail image, and I'd like just the first result to have that.

Thanks!
ROY
Jr. Member
Jr. Member
 
Posts: 168
Joined: Thu Jul 29, 2010 5:47 am

Re: List recent posts but style first result differently?

Postby david » Thu Aug 05, 2010 1:07 am

?php $posts = get_posts( "category=4&numberposts=6" ); ?>
<?php if( $posts ) : $count = 0; ?>
<?php foreach( $posts as $post ) : setup_postdata( $post );
if($count == 0):
?>
<a href="<?php the_permalink(); ?>"><img src="<?php echo get_post_meta($post->ID, "image_preview", true);?>" width="130" height="73" alt="<?php the_title(); ?>" /></a>
<?php endif; ?>
<h3><a href="<?php echo get_permalink($post->ID); ?>" ><?php if (strlen($post->post_title) > 60) {
echo substr(the_title('', '', FALSE), 0, 150) . '';
} else {
the_title();
} ?></a> <span class="date">(</span><a href="<?php echo get_permalink($post->ID); ?>#comments" ><?php comments_number('0', '1', '%'); ?></a><span class="date">)</span></h3>
<?php the_excerpt(); ?>
<?php $count++; endforeach; ?>
<?php endif; ?>
Try this once.
david
Jr. Member
Jr. Member
 
Posts: 154
Joined: Thu Jul 29, 2010 6:03 am

Re: List recent posts but style first result differently?

Postby ROY » Thu Aug 05, 2010 1:07 am

Thanks , works perfectly!
ROY
Jr. Member
Jr. Member
 
Posts: 168
Joined: Thu Jul 29, 2010 5:47 am

Re: List recent posts but style first result differently?

Postby david » Thu Aug 05, 2010 1:08 am

ou're welcome.:)

Thanks


If solve the thread, plz mark it as resolved.
david
Jr. Member
Jr. Member
 
Posts: 154
Joined: Thu Jul 29, 2010 6:03 am

  • Ads

Return to Wordpress General Help

Who is online

Users browsing this forum: No registered users and 1 guest

cron