...

View Full Version : Adding an alt attribute to an image link through php



cjwsb
07-07-2005, 07:34 PM
Hello all,

First of all, let me say that I know very little about php, and have just about reached my limit with this one.

I use SPGM for a photo gallery script on my website. Test site is here (http://www.bartlett-family.net/chrisbartlett/photography/galleries/).

Now, you can see the little folder images. What I'd very much like to do is add an ALT attribute to those images. Now, I WAS able to do this same thing (but with a title attribute) to the text links right next to the images. Hover over the text links to see. That's not native of SPGM. I added it.

But I can't figure out how to do the same thing to the images themselves! It's driving me quite crazy.

I made a text file version of the php file that controls everything for the script so you can see it here (http://www.bartlett-family.net/chrisbartlett/photography/galleries/spgm.txt). Could someone have a look, please, and help me figure this out? Mucho appreciated!

Chris

Len Whistler
07-07-2005, 09:52 PM
That is one bloated script.

You should start from scratch and use a PHP/MySQL image gallery. With MySQL you can have a unique img alt for each image.

cjwsb
07-07-2005, 11:37 PM
That is one bloated script.

You should start from scratch and use a PHP/MySQL image gallery. With MySQL you can have a unique img alt for each image.

While I appreciate the thought, that doesn't help. I did not write it. Nor can I start from scratch because I don't know php. It is a bit bloated, yes, but it's also easy, extremely portable, and valid XHTML 1.0 Strict.

How many php-written ANYTHING is that? Not too many.

Anyone know how I can add this attribute? It HAS to be possible. I already did it to on portion.

Chris

bfsog
07-08-2005, 12:54 AM
Hmm?

You just want the image to have tooltip text?

<img src="file.jpg" alt="text here" />

cjwsb
07-08-2005, 01:23 AM
Hmm?

You just want the image to have tooltip text?

<img src="file.jpg" alt="text here" />
LOL, I wish it were that simple. I can't add it that way. The HTML file you see through "View Source" is generated from the php file I linked to. The tooltip text has to be added somewhere in there. I just don't know where, and can't find it.

Chris

Len Whistler
07-08-2005, 01:39 AM
It HAS to be possible. I already did it to on portion.

You must have added the img alt to one portion of an if/else statement. Go back and add the img alt info to the rest of the block of code.

cjwsb
07-08-2005, 01:55 AM
You must have added the img alt to one portion of an if/else statement. Go back and add the img alt info to the rest of the block of code.
Well, that's exactly what I'm having trouble with. WHAT block of code? I appreciate your guys help, I really do. I'm just frustrated as hell because I've gotten so close to my goal on my own (even without knowing php at all) only to get hung up now.

Ok, if you look at the source code of the page, you'll see this:


<td class="td-galitem-title"><img alt="Just a transparent spacer image" src="http://www.chrisbartlett.net/pix/spacer.png"/>
<a title="Enter the Cityscape Photos gallery here" href="index.html?spgmGal=Cityscape_Photos" class="td-galitem-title">Cityscape Photos</a>
I was able to add the ALT and the spacer images because I noticed the "class="td-galitem-title". From that, I was able to find out where to add what I needed in the php file. Basically just methodical detective work and luck.

Now, the other code in the source is this:


<a href="index.html?spgmGal=Cityscape_Photos" class="td-galitem-title"><img src="flavors/default/folder.jpg" alt="" class="img-folder" width="46" height="44" /></a>

I need to add an ALT attribute to that so it's not blank. But if you'll notice, it uses the same class. Now, I have looked everywhere (including the same block of code that I added all the above crap to) and can't find squat.

The only other idea I had was the class="img-folder" could be what I wanted. Doesn't seem to be. I did find this in the php file:


// key in $cfg | ALT value | CLASS value | alternative (if resource is N/A)
array('gallerySmallIcon', '', CLASS_IMG_FOLDER, ''),
array('galleryBigIcon', '', CLASS_IMG_FOLDER, '&raquo;'),

But what does that tell me?!

I'd really appreciate it if someone could help me figure this out. It's gotta be something simple that I just don't see...

Chris

cjwsb
07-08-2005, 08:11 PM
Wait a sec!

I DID IT! Well, sorta...

Ok, it's now


// key in $cfg | ALT value | CLASS value | alternative (if resource is N/A)
array('gallerySmallIcon', 'Enter the '.$strHtmlGalleryName.' gallery here', CLASS_IMG_FOLDER, ''),
array('galleryBigIcon', 'Enter the '.$strHtmlGalleryName.' gallery here', CLASS_IMG_FOLDER, '&raquo;'),

Great, but one other thing. If you go to the site and hover over the TEXT link right next to the folder icon, let's say the landscape gallery, it says, "Enter the Landscape Photos gallery here". However, by hovering over the icon itself, you'll only get, "Enter the gallery here". Why is the '.$strHtmlGalleryName.' variable (is that the right term?!) not working?

Chris

joeframbach
07-08-2005, 08:24 PM
i know it's off topic here, but can you comment out that Begin statement at the end of the page in the JS.

<!-- // Begin

cjwsb
07-08-2005, 08:42 PM
i know it's off topic here, but can you comment out that Begin statement at the end of the page in the JS.

<!-- // Begin
Ummmm... Well, sure. But might I ask why?

Chris

PS. I used to live around Pittsburgh; in Oakmont, Gibsonia, & Bethel Park! Geatest city on earth, man.

joeframbach
07-09-2005, 04:31 AM
it's just floating there. if you did something like that in a more structured language, you'd get some kind of "identifier expected" exception, or something.

cjwsb
07-09-2005, 04:50 AM
Ok,

I'll get around to changing it soon. Can anyone PLEASE help me figure out this php problem.

It's pretty important to me for WCAG-3 compatibility reasons.

I know it's a big php file with crappy formatting, but I'd really appreciate it if someone could tackle this.

Chris

joeframbach
07-09-2005, 05:05 AM
change lines 925 and 953 to


print ' alt="Enter the '.$strHtmlGalleryName.' gallery here" class="'.CLASS_IMG_GALICON.'" />';

and see where it goes from there.

joeframbach
07-09-2005, 05:13 AM
hmm. it could also be lines 427 and 428.


array('gallerySmallIcon', 'Enter the '.$strHtmlGalleryName.' gallery here', CLASS_IMG_FOLDER, ''),
array('galleryBigIcon', 'Enter the '.$strHtmlGalleryName.' gallery here', CLASS_IMG_FOLDER, '&raquo;'),

cjwsb
07-09-2005, 06:47 AM
hmm. it could also be lines 427 and 428.


array('gallerySmallIcon', 'Enter the '.$strHtmlGalleryName.' gallery here', CLASS_IMG_FOLDER, ''),
array('galleryBigIcon', 'Enter the '.$strHtmlGalleryName.' gallery here', CLASS_IMG_FOLDER, '&raquo;'),

It already IS that, unless I'm somehow reading it wrong.

Chris

cjwsb
07-09-2005, 07:12 AM
change lines 925 and 953 to


print ' alt="Enter the '.$strHtmlGalleryName.' gallery here" class="'.CLASS_IMG_GALICON.'" />';

and see where it goes from there.
Done. Changed nothing. Argh... Any other thoughts, mate?

Chris

joeframbach
07-09-2005, 05:03 PM
That is one bloated script.

You should start from scratch and use a PHP/MySQL image gallery. With MySQL you can have a unique img alt for each image.

QFT..

cjwsb
07-09-2005, 05:11 PM
QFT..
QFT?!

Chris

Bill Posters
07-09-2005, 08:35 PM
You just want the image to have tooltip text?

<img src="file.jpg" alt="text here" />

Fwiw, the correct way to implement that kind of tooltip is to use the title attribute.

joeframbach
07-10-2005, 12:13 AM
sorry. QFT means "quoted for truth."

give that "title" thing a shot. let us know how it turns out!

delinear
07-10-2005, 12:32 AM
Fwiw, the correct way to implement that kind of tooltip is to use the title attribute.

Going way off topic now, but I used the title tag exclusively for a while since it seemed to have more browser compatability than the alt tag, but for XHTML1.0 Strict validation it seems the alt tag is required, so now I use both. I don't know if this is the correct way to do it but it seems to validate :o

Just thought it was worth mentioning if standards compliance is an issue :)

Bill Posters
07-10-2005, 07:24 AM
Going way off topic now, but I used the title tag exclusively for a while since it seemed to have more browser compatability than the alt tag, but for XHTML1.0 Strict validation it seems the alt tag is required, so now I use both. I don't know if this is the correct way to do it but it seems to validate :o

Just thought it was worth mentioning if standards compliance is an issue :)

The alt attribute is indeed required by the spec, but the (optional) title attribute is the correct one to use if you wish to implement tooltips. IE will (additionally) display the contents of the alt attribute as a tooltip (though I think it will display the contents of the title attr. if both are present), for reasons which probably fall somewhere between customer service and MNS's typical willful ignorance (of the standards).

The title attr. can be added do any element, whereas the alt attr. is only for use with the [i]img[i/] element.

Incidentally, you should perhaps avoid using one for the other as the alt and title attributes serve slightly different purposes.

The alt attr. serves as a textual 'replacement' of the image itself (typically describing its contents in some way), whereas the title attr. serves to offer additional information about the function of the image.

A typical example where both could be used would be on img links, where the alt attr. would described the image and the title attr. would describe the function or destination of the link.

Anyhoo… ;)

cjwsb
07-10-2005, 07:34 AM
Holy hijacked thread, Batman!

Anyone know how to solve my dilemna?

I appreciate those who've tried!

Chris



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum