Author Topic: [MOD] Add keywords / description in image alt tag  (Read 21411 times)

0 Members and 1 Guest are viewing this topic.

Offline ruudvroon

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • AFTERTHEPARTY.NL
[MOD] Add keywords / description in image alt tag
« on: October 28, 2005, 08:04:07 PM »
How can I add the keywords (without links) to the alt description?
I tried to add  {image_keywords} to the media template, but I get random keywords  :?
« Last Edit: December 29, 2007, 03:28:25 PM by mawenzi »

Offline lemccoy

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • DrunkIsland
Re: [Req]Add keywords in image alt
« Reply #1 on: October 31, 2005, 11:43:03 PM »
Has anyone figured out how to do this? I see the image keywords is coming from the random image in the page.  How do you get the main image to have it's main keywords?
Thanks

Offline ruudvroon

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • AFTERTHEPARTY.NL
Re: [Req]Add keywords in image alt
« Reply #2 on: November 02, 2005, 12:49:22 PM »
Please someone, I need it because i want google image search can find the images.

Offline ruudvroon

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • AFTERTHEPARTY.NL
Re: [Req]Add keywords in image alt
« Reply #3 on: November 02, 2005, 02:00:45 PM »
I made a sollution:

Open includes/functions.php

Find:
Code: [Select]
  else {
    $user_name = $lang['userlevel_guest'];
    $user_name_link = $user_name;
  }

Add below:
Code: [Select]
if ($detailed_view) {
  if (!empty($image_row['image_keywords'])) {
    $split_keywords2 = explode(" ", $image_row['image_keywords']);
    $keywords2 = "";
    foreach ($split_keywords2 as $key2 => $val2) {
      $keywords2 .= (($keywords2 != "" ) ? ", " : "")."$val2";
    }
}



   $site_template->register_vars(array(
     "alt_keywords" => $keywords2,
   ));
 }

Open templates/{your_template}/media/jpg.html

Find:
Code: [Select]
alt="{image_name}"

Replace with:
Code: [Select]
alt="{image_name}, {alt_keywords}"

Is there someone who can add the , in the {alt_keywords} because you now you also get a , when there're no keywords?

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Req]Add keywords in image alt
« Reply #4 on: November 02, 2005, 02:20:45 PM »
Code: [Select]
alt="{image_name}{if alt_keywords}, {alt_keywords}{endif alt_keywords}"
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline lemccoy

  • Jr. Member
  • **
  • Posts: 90
    • View Profile
    • DrunkIsland
Re: [Req]Add keywords in image alt
« Reply #5 on: November 02, 2005, 03:40:31 PM »
Perfect.  Thanks a bunch guys.

Offline edwin

  • Full Member
  • ***
  • Posts: 199
    • View Profile
    • http://www.foto-janssen.nl
Re: [Req]Add keywords in image alt
« Reply #6 on: November 03, 2005, 12:59:25 AM »
mayby an stupid question, but what if i want to show the image description ?

Offline ruudvroon

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • AFTERTHEPARTY.NL
Re: [Req]Add keywords in image alt
« Reply #7 on: November 03, 2005, 07:54:40 AM »
Open includes/functions.php

Find:
Code: [Select]
  else {
    $user_name = $lang['userlevel_guest'];
    $user_name_link = $user_name;
  }

Add below:
Code: [Select]
if ($detailed_view) {
$description2 = (!empty($image_row['image_description'])) ? format_text($image_row['image_description'], 1) : REPLACE_EMPTY;
  if (!empty($image_row['image_keywords'])) {
    $split_keywords2 = explode(" ", $image_row['image_keywords']);
    $keywords2 = "";
    foreach ($split_keywords2 as $key2 => $val2) {
      $keywords2 .= (($keywords2 != "" ) ? ", " : "")."$val2";
    }
}
   $site_template->register_vars(array(
     "alt_keywords" => $keywords2,
     "alt_description" => $description2,
   ));
 }

Open templates/{your_template}/media/jpg.html

Find:
Code: [Select]
alt="{image_name}"

Replace with:
Code: [Select]
alt="{image_name}{if alt_description}, {alt_description}{endif alt_description}"

Offline edwin

  • Full Member
  • ***
  • Posts: 199
    • View Profile
    • http://www.foto-janssen.nl
Re: [Req]Add keywords in image alt
« Reply #8 on: November 03, 2005, 04:06:18 PM »
Great this is the right way,

it works in detailview, but is it also possible in the categoriesview and on the indexpage

Offline bibabobu

  • Sr. Member
  • ****
  • Posts: 311
  • Technische und künstlerische Gravuren
    • View Profile
    • Technische und künstlerische Gravuren für die gesamte Metall-, Kunststoff- und Papierindustrie
Re: [Req]Add keywords in image alt
« Reply #9 on: November 03, 2005, 05:13:54 PM »
Yeah thats all great.

Is it possible to have the image description AND the keywords :?:

That would be absolut fantastic  :mrgreen:

Offline ruudvroon

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
    • AFTERTHEPARTY.NL
Re: [Req]Add keywords in image alt
« Reply #10 on: November 03, 2005, 06:37:10 PM »
just use the code from the description:

Open templates/{your_template}/media/jpg.html

Find:
Code: [Select]
alt="{image_name}{if alt_description}, {alt_description}{endif alt_description}"
Replace with:
Code: [Select]
alt="{image_name}{if alt_keywords}, {alt_keywords}{endif alt_keywords}{if alt_description}, {alt_description}{endif alt_description}"
Or:
Code: [Select]
alt="{image_name}{if alt_description}, {alt_description}{endif alt_description}{if alt_keywords}, {alt_keywords}{endif alt_keywords}"

Offline edwin

  • Full Member
  • ***
  • Posts: 199
    • View Profile
    • http://www.foto-janssen.nl
Re: [Req]Add keywords in image alt
« Reply #11 on: November 04, 2005, 02:32:34 AM »
Ruud, can you please take a look how i can place it in index page and the categoriespage

thanks in advance

Offline bibabobu

  • Sr. Member
  • ****
  • Posts: 311
  • Technische und künstlerische Gravuren
    • View Profile
    • Technische und künstlerische Gravuren für die gesamte Metall-, Kunststoff- und Papierindustrie
Re: [Req]Add keywords in image alt
« Reply #12 on: November 04, 2005, 01:00:01 PM »
Thanks ruudvroon :D

Great MOD i think.

It is working perfect for me.

Just one thing, which could irritate the beginners.
You forgot the alt="" tag in front of the code which must be replaced.

Code: [Select]
alt="{image_name}{if alt_description}, {alt_description}{endif alt_description}{if alt_keywords}, {alt_keywords}{endif alt_keywords}" :mrgreen:

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: [Req]Add keywords in image alt
« Reply #13 on: November 04, 2005, 02:42:45 PM »
little correction
these lines:
Code: [Select]
     "alt_keywords" => $keywords2,
     "alt_description" => $description2,
should be like this:
Code: [Select]
     "alt_keywords" => str_replace("\"", """, $keywords2),
     "alt_description" => str_replace("\"", """, $description2),

to avoid conflict if a description or a keyword contain a quote
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline edwin

  • Full Member
  • ***
  • Posts: 199
    • View Profile
    • http://www.foto-janssen.nl
Re: [Req]Add keywords in image alt
« Reply #14 on: November 04, 2005, 04:48:16 PM »
V@no, master of 4images, can you tell me what and wich pages i have to change if i want to show the description also on the indexpage(home) and the categoriespage and not only the detailview

 

Post your comments here