php - Echo ALT attribute of random image -


i have little script displays random image, is:

<img src="<?php echo bloginfo('template_url');?>/img/members/00<?php $random = rand(1,7); echo $random; ?>.jpg"alt="[ random image ]"> 

this makes image src src="example.com/images/001.jpg" alt="[ random image ]"> (1,7) in script adds number of image 001.jpg 007.jpg.

now change "[ random image ]" in "$my_alt" , have display (echo) alt attribute of image in <h2 class="myalt">...</h2> tag.

i'm not of coder, don't know how this. believe first need give my_alt value. go by:

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"}

and want value of alt placed add code: <h2 class="myalt"><?php echo $my_alt(); ?></h2>

am doing correct, right way go? said i'm not @ coding, help.

i got problem. try see if works:

<!-- gonna make sample template may understand how use solution specific issue -->  <div class="imagecontainer">     <img src="something" alt="image1" />     <h2 class="myalt"></h2> </div> <div class="imagecontainer">     <img src="something" alt="image2" />     <h2 class="myalt"></h2> </div> <div class="imagecontainer">     <img src="something" alt="image3" />     <h2 class="myalt"></h2> </div> <div class="imagecontainer">     <img src="something" alt="image4" />     <h2 class="myalt"></h2> </div>  <script> $('.imagecontainer').each(function(){     $(this).find('.myalt').html($(this).find('img').attr('alt')); }); </script> 

it show respective alt below every image.

for particular 2 images

// giving alt dynimically     $('img').each(function(){         if($(this).attr('src')==='image 001.jpg'){             $(this).attr('alt','person x');         }         else if($(this).attr('src')==='image 002.jpg'){             $(this).attr('alt','person y');         }     }); 

its idea, need modify suit particular problem. luck. i hope helps


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -