Zen Cart Logo
Forums / Templates, Stylesheets, Page Layout / Adding text to additional images individually

Adding text to additional images individually

Locked

Views: 5,054

Results 1 to 20 of 27
This thread is locked. New replies are disabled.
17 Dec 2008, 10:51 PM
#1
palomapottery avatar

palomapottery

New Zenner

Join Date:
Dec 2008
Posts:
7
Plugin Contributions:
0

Adding text to additional images individually

Hello,
I'm trying to add text to each individual additional image for each product. I have found some threads that have shown me how to add text to all pages. I would like to find a way to "title" each image individually.

I use a custom template and my ZenCart info is:
Server Host: host.nwwebdev.com (127.0.0.1)
Database Host: localhost (127.0.0.1)
Server OS: Linux 2.6.18-028stab059.6
Database: MySQL 5.0.22

I appreciate any help available. In order for me to properly communicate to my customers what they are looking at in each image, I have found I do need to "title" each image. I tried to get around this problem by using images with attributes, but it just isn't sufficient.

My website is https://www.palomapottery.com

Thanks you for your time!!!

5 Jan 2009, 4:57 AM
#2
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Adding text to additional images individually

I am also very interested in this as my attributes hinge on my additional images. Could somebody please point us in the right direction?

5 Jan 2009, 6:45 AM
#3
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Adding text to additional images individually

You should be able to process the image titles in /includes/modules/additional_images.php.

To avoid having to put masses of single-use text in this file, I would take the approach of defining a set of captions in a language file, using constant names based on the product additional image names, and then as each image is processed, check if a corresponding constant is defined and insert its value into the output.

5 Jan 2009, 4:04 PM
#4
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Adding text to additional images individually

Ooh this is exactly what I need to do. Is there, perhaps, an example or more information on how to code this? Would greatly appreciate if you could point me in the right direction:D

5 Jan 2009, 5:10 PM
#5
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Adding text to additional images individually

It seems like a useful mod, so I'm working on it. It appears to be pretty simple.

5 Jan 2009, 5:41 PM
#6
yellow1912 avatar

yellow1912

Totally Zenned

Join Date:
Oct 2006
Posts:
5,422
Plugin Contributions:
0

Re: Adding text to additional images individually

gjh42:

It seems like a useful mod, so I'm working on it. It appears to be pretty simple.
Wouldn't it be better to have a table to store images, with name, link, etc? I'm thinking of going that way.

5 Jan 2009, 6:05 PM
#7
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Adding text to additional images individually

Here is a beta version of Additional Image Titles. It doesn't have a readme yet, so here are the instructions:

Unzip on your pc, navigate to /includes/modules/ and change /your_template/ to the name of your custom template.

Open /includes/languages/english/extra_definitions/additional_image_titles.php and add defines for your additional image files, like this:

define ('ADDIMG_RINGS_RING23_01_JPG','Additional View #1');//title for /images/rings/ring23_01.jpg
define ('ADDIMG_HOE_SIDE_JPG','Side View');//title for /images/hoe_side.jpg

The code that does the work in /includes/modules/your_template/additional_images.php is quite simple:```php
// additional image titles - gjh42 20090105
$badchars = array('/','.','-',' ');//not allowed in constant names
$add_const_name = 'ADDIMG_' . strtoupper(str_replace($badchars,'_',$file));
// uses file ext and subdir if any in constant name, e.g. ADDIMG_RINGS_RING23_01_JPG for /images/rings/ring23_01.jpg
// define constants in /includes/languages/english/extra_definitions/additional_image_titles.php
// if any other characters could be used in filename, add them to $badchars
$link = (defined($add_const_name))? $add_const_name . '<br />' . $link: $link;
// /additional image titles - gjh42 20090105
// List Box array generation:


Sure, you could use a db table to do this instead. If you want to do another version, go ahead:)
5 Jan 2009, 6:56 PM
#8
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Adding text to additional images individually

WOW I haven't tested this yet but I have to say MANY THANKS!

The Zen community is awesome so far (I came from Oscommerce).

:D

5 Jan 2009, 8:01 PM
#9
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Adding text to additional images individually

Here is an enhancement to allow styling the titles as desired:

    $link = (defined($add_const_name))? '<h4 class="addImgTitle">' . $add_const_name . '</h4>' . $link: $link;
```Add to your stylesheet

.addImgTitle {font-size: 1.0em; /*any other properties desired*/}
6 Jan 2009, 5:44 AM
#10
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Adding text to additional images individually

gjh42:

Here is a beta version of Additional Image Titles. It doesn't have a readme yet, so here are the instructions:

Unzip on your pc, navigate to /includes/modules/ and change /your_template/ to the name of your custom template.

Open /includes/languages/english/extra_definitions/additional_image_titles.php and add defines for your additional image files, like this:

define ('ADDIMG_RINGS_RING23_01_JPG','Additional View #1');//title for /images/rings/ring23_01.jpg
define ('ADDIMG_HOE_SIDE_JPG','Side View');//title for /images/hoe_side.jpg

The code that does the work in /includes/modules/your_template/additional_images.php is quite simple:```php
// additional image titles - gjh42 20090105
$badchars = array('/','.','-',' ');//not allowed in constant names
$add_const_name = 'ADDIMG_' . strtoupper(str_replace($badchars,'_',$file));
// uses file ext and subdir if any in constant name, e.g. ADDIMG_RINGS_RING23_01_JPG for /images/rings/ring23_01.jpg
// define constants in /includes/languages/english/extra_definitions/additional_image_titles.php
// if any other characters could be used in filename, add them to $badchars
$link = (defined($add_const_name))? $add_const_name . '<br />' . $link: $link;
// /additional image titles - gjh42 20090105
// List Box array generation:

> 
> Sure, you could use a db table to do this instead. If you want to do another version, go ahead:)

Hey Glenn, I've followed your directions to a tee... I'm just getting the ADDIMG text displaying on my product page, for example " ADDIMG_BULK10_CURLY_JPG" not the "Curly" text I assigned.  

The image "bulk10_curly.jpg" displays just fine. 

![](http://gautamaswamy.com/images/curly.jpg)
6 Jan 2009, 10:19 AM
#11
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Adding text to additional images individually

Hmm... it is finding the defined constant, or else it wouldn't display any text, but what it is displaying is the value of the variable (which is the constant name). I'll have to think a bit on how to get the constant's value displayed. Have been researching and not finding any information whatsoever on it.

6 Jan 2009, 11:01 AM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Adding text to additional images individually

Should have looked more thoroughly through the PHP function list... try this:```php
$link = (defined($add_const_name))? '<h4 class="addImgTitle">' . constant($add_const_name) . '</h4>' . $link: $link;

returns the value of the content treated as a constant name.

Principle tested and works.
6 Jan 2009, 3:08 PM
#13
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Adding text to additional images individually

It's working!!! Thanks so much Glenn... you really helped me out!

9 Jan 2009, 11:32 PM
#14
palomapottery avatar

palomapottery

New Zenner

Join Date:
Dec 2008
Posts:
7
Plugin Contributions:
0

Re: Adding text to additional images individually

I'm still having trouble making this work. I've followed instructions and am not getting any results at all. My knowledge of php is very little, but your instructions are easy to understand. I do have a rather customized template and that may be the reason it's not working.

Can you make this an admin application?

I am so grateful for all your time! I will continue to try and make it work as you instructed. However, if you have any thoughts of adding this mod as an admin application I would just LOVE that!

Thank you again!

10 Jan 2009, 8:26 AM
#15
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Adding text to additional images individually

An admin-editable mod would require database modifications and considerably more work to build the functionality. Especially with v2.0 coming out soon, I do not plan to get into this for the current release.

Can you post a link to your site to see what you have and how it is behaving?

11 Jan 2009, 5:32 PM
#16
palomapottery avatar

palomapottery

New Zenner

Join Date:
Dec 2008
Posts:
7
Plugin Contributions:
0

Re: Adding text to additional images individually

Thank you so much for your response.

I am now having more luck with adding the titles to the images. I was previously working with images that have long file names with spaces in the file names. I tried it with images without any spaces in filenames and it worked!!

I am so excited to have this capability - thank you so much for all your time!

I will have to change the filenames I suppose. Unless you have another suggestion.

Thank you again! You have been very helpful!!

For your reference, below is a link to a page with images that didn't work with adding the titles:
http://www.palomapottery.com/catalog/index.php?main_page=product_info&cPath=14&products_id=59

Other pages with images that are working with adding the titles:
http://www.palomapottery.com/catalog/index.php?main_page=product_info&cPath=16&products_id=18

11 Jan 2009, 7:25 PM
#17
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Adding text to additional images individually

I just noticed another problem... when putting the path in the language file for an image that's in a folder, it isn't working.

My image path in zencart is in images/bulk/bulk10_curly.jpg

I put:
define ('ADDIMG_BULK_BULK10_CURLY_JPG','curly');

But it doesn't bring up any text at all.

Images in the root image folder seem to work just fine, any ideas?

11 Jan 2009, 7:30 PM
#18
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Adding text to additional images individually

Just because Microsoft lets users make file/folder names with spaces doesn't mean it's a good idea...
It is a universal computer best practice to use only letters, numbers, _, -, . and perhaps one or two other characters in filenames. Keeping letters lower case is also a good idea, as some applications are case sensitive and forgetting what you capitalized can cause unexpected problems.

Hmm, I'll have to investigate that. I thought it would work with subfolders, but wasn't certain. It will require some detailed debugging to see exactly how the file/folder names are handled.

11 Jan 2009, 7:33 PM
#19
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Adding text to additional images individually

Ok I agree with all that, but is there something wrong with the way I have it set up? I'm not using any funny characters at all.

11 Jan 2009, 8:16 PM
#20
swamyg1 avatar

swamyg1

Zen Follower

Join Date:
Dec 2008
Location:
San Fran
Posts:
382
Plugin Contributions:
0

Re: Adding text to additional images individually

gjh42:

Just because Microsoft lets users make file/folder names with spaces doesn't mean it's a good idea...
It is a universal computer best practice to use only letters, numbers, _, -, . and perhaps one or two other characters in filenames. Keeping letters lower case is also a good idea, as some applications are case sensitive and forgetting what you capitalized can cause unexpected problems.

Hmm, I'll have to investigate that. I thought it would work with subfolders, but wasn't certain. It will require some detailed debugging to see exactly how the file/folder names are handled.

Sorry I didn't see your part about the "DEBUGGING" thing... sorry about that. That's no problem, I undestand. I'll just stick with them in the root folder for now.