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

Adding text to additional images individually

Locked

Views: 5,067

Results 21 to 27 of 27
This thread is locked. New replies are disabled.
11 Jan 2009, 9:25 PM
#21
gjh42 avatar

gjh42

Black Belt

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

Adding text to additional images individually

The $file variable holds the filename only; $base_image has the subfolder (if any) plus filename.This code will handle any file (as long as it doesn't have spaces), and put the text above or below the image (depending on the value of a constant ADDIMG_TEXT_TOP which should be set in the definitions file):php // additional image titles $badchars = array('/','\\','.','-',' ');//not allowed in constant names // if any other characters could be used in filepath, add them to $badchars $add_const_name = 'ADDIMG_' . strtoupper(str_replace($badchars,'_',$base_image)); if (defined($add_const_name)) {//add text above or below images $link = (ADDIMG_TEXT_TOP)? '<div class="addImgTitle">' . constant($add_const_name) . '</div>' . $link: $link . '<div class="addImgTitle">' . constant($add_const_name) . '</div>'; } // /additional image titles // List Box array generation: Add to the definition file:```php
define ('ADDIMG_TEXT_TOP','true'};//change to false to put text below images

The $badchars setup is intended to convert spaces, but apparently is unable to do so. It will handle / \ . - characters.
12 Jan 2009, 1:47 AM
#22
palomapottery avatar

palomapottery

New Zenner

Join Date:
Dec 2008
Posts:
7
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.

Thank you for your suggestions and info on naming images and filenames. Much appreciated! I normally try not to use spaces. From now on I will be sure to follow that rule more rigorously. Thanks!

12 Jan 2009, 5:18 AM
#23
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

A bit more study revealed that $base_image has "images/" plus the subfolder (if any) plus filename. This requires a bit more processing, as shown:```php
$add_const_name = 'ADDIMG_' . strtoupper(str_replace($badchars,'_',ereg_replace('(^images/)','',$base_image)));

$add_const_name = 'ADDIMG' . strtoupper(ereg_replace('(^images/)[/\\.-]','_',$base_image)));//test if this works 
echo $base_image . $add_const_name;

Please try the second version so I can get more verification that it works.

PS - 
I really like your site (I'm a potter too.) I wish you would put the "powered by Zen Cart" link back into the footer so you can add it to the showcase as an example of what can really be done with the platform.
12 Jan 2009, 6:52 AM
#24
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

After local testing, here is the final version of the additional image titles code:```php
// additional image titles
$add_img_const = 'ADDIMG_' . strtoupper(ereg_replace('[/\.-]','_',substr_replace($base_image,'',0,7)));// if any other characters could be used in filepath, add them to list [ ]
if (defined($add_img_const)) {//add text above or below images
$link = (ADDIMG_TEXT_TOP)? '<h4 class="addImgTitle">' . constant($add_img_const) . '</h4>' . $link: $link . '<h4 class="addImgTitle">' . constant($add_img_const) . '</h4>';
}
// /additional image titles

23 Jan 2009, 5:14 AM
#25
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

Additional Image Titles is now available in Free Addons.

See the support thread for questions and further help.

22 Jan 2010, 1:26 PM
#26
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,114
Plugin Contributions:
56

Re: Adding text to additional images individually

Wow! This installed like a dream. Thank you for the contribution!

14 Oct 2010, 3:17 AM
#27
524cw avatar

524cw

New Zenner

Join Date:
Sep 2008
Posts:
53
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.

They should teach this in public schools. Along with "why you can't make digital pictures bigger".