Apply a specific class to the first item in a series with PHP

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2010-04-02T15:58:03Z Indexed on 2010/04/02 16:03 UTC
Read the original article Hit count: 276

Filed under:
|

I have a php script that echoes a series of uploaded images and I need to apply a class to the first image echoed in the series. Is this possible? For example, if I want to display 10 images and apply a class to only the first image, how would I go about it?

Here is the code, I am working with:

<div id="gallery">  
<?php
query_posts('cat=7');
while(have_posts())
{
the_post();
$image_tag = wp_get_post_image('return_html=true');
$resized_img = getphpthumburl($image_tag,'h=387&w=587&zc=1'); 
$url = get_permalink();
$Price ='Price'; 
$Location = 'Location';
$title = $post->post_title;
echo "<a href='$url'><img src='$resized_img' width='587' height='387' ";
echo "rel=\"<div class='gallery_title'><h2>";
echo $title;
echo "</h2></div>";
echo "<div class='pre_box'>Rate:</div><div class='entry'>\$";
echo get_post_meta($post->ID, $Price, true);
echo "</div><div class='pre_box'>Location:</div><div class='entry'>";
echo get_post_meta($post->ID, $Location, true);
echo "</div>\"";
echo  "'/></a>";
echo "";
}
?>

On line 13, the code looks like this:

echo "<a href='$url'><img src='$resized_img' width='587' height='387' ";

For the first item only, I need it to look like this:

echo "<a href='$url' class='show'><img src='$resized_img' width='587' height='387' ";

© Stack Overflow or respective owner

Related posts about php

Related posts about html