Echo ALT attribute of random image
<p>I have this little script that displays a random image, which is:</p>

<pre><code>&lt;img src="&lt;?php echo bloginfo('template_url');?&gt;/img/members/00&lt;?php $random = rand(1,7); echo $random; ?&gt;.jpg"alt="[ Random Image ]"&gt;
</code></pre>

<p>This makes the image src <code>src="example.com/images/001.jpg" alt="[ Random Image ]"&gt;</code> the (1,7) in the script adds the number of the image <code>001.jpg</code> to <code>007.jpg</code>.</p>

<p>Now what I would like is to change the <code>"[ Random Image ]"</code> in to <code>"$my_alt"</code> and have it display (echo) the alt attribute of the image in a <code>&lt;h2 class="myAlt"&gt;...&lt;/h2&gt;</code> tag.</p>

<p>I'm not that of a coder, so I don't really know how to do this. I believe I would first need to give <code>my_alt</code> a value. So I would go by:</p>

<p><code>if {image src="example.com/images/001.jpg" $my_alt = "My first Alt"}
else if {image src="example.com/images/002.jpg" $my_alt = "My second Alt"}</code></p>

<p>and then where I want the value of the alt to be placed add the code:
<code>&lt;h2 class="myAlt"&gt;&lt;?php echo $my_alt(); ?&gt;&lt;/h2&gt;</code></p>

<p>Am I doing this correct, is this the right way to go? Like I said I'm not that good at coding, so thanks for the help.</p>