Where is the alt text printing located

Hi,
I want to change the alt text location for my thumbnails.
Using printLatestImages() , the alt text is the same as the title but I want to change it, Iooked up a really old thread:

http://forum.zenphoto.org/discussion/1719/changing-alt-text-for-images

I looked through template function but I cannot find where:

alt="<?php echo getImageTitle(); ?>"

is located. The documentation did not help much, anyone know where that line of code is located?

Tags:

Comments

  • acrylian Administrator
    edited March 27

    It is located within the function printImageStatistic() of the image_album_statistics plugin within the lines 577-590 depending on what options used. It uses the core object model and therefore is a bit different.

    Recommended way for customisations: Copy, rename and modify the function (e.g. mytheme_printImageStatistics()) and place it within your theme's function.php.

  • Found it, not very good with syntax though.

    If I just want to add "free photo" at the end of the alt text

    echo '<img src="' . html_encode(pathurlencode($image->getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE))) . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" alt="' . html_encode($image->getTitle()) ."\" />\n";

    How would I just append "free photo" at the end of the title for the alt text, keep getting the wrong syntax.

  • acrylian Administrator

    Appending text is quite basic like this html_encode($image->getTitle()) . ' free photo'

  • I get an error when I do:

    echo '<img src="' . html_encode(pathurlencode($image->getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE))) . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" alt="' . html_encode($image->getTitle()) . 'free photo' "\" />\n";

    is there some kind of backslash that I need to do?

  • acrylian Administrator
    edited March 28

    You have an issue with your quotes here. A double quote is wrong. At the end it should be something like . 'free photo"'. " />\n";. You can also just end like . 'free photo" />'; The \n part is just for code formatting a new line and has no other functionality.

  • Both:

    echo '<img src="' . html_encode(pathurlencode($image->getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE))) . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" alt="' . html_encode($image->getTitle()) . 'free photo"'\" />\n";

    and

    echo '<img src="' . html_encode(pathurlencode($image->getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE))) . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" alt="' . html_encode($image->getTitle()) .'free photo"\" />'\n";

    Give errors, I've tried a lot of different interations, can't get it to work.

  • acrylian Administrator

    Well, you didn't pay atention to the details. Look at your quotes. Whatever you open, you also need to close. Especially the last one is really wrong. This is really PHP basics, sorry…

    Try this:
    `echo '<img src="' . html_encode($image->getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE)) . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" alt="' . html_encode($image->getTitle()) . 'free photo"'. " />\n";

    If it doesn't work the error might also be in another line already.

  • wibbi Member
    edited April 5

    A better way is to duplicate the function you need, give him a new name, edit it and use it.

    You can find the file and point of an function in the Zenphoto docs.
    http://docs.zenphoto.org/
    Use the search-box at top-right. (works only with function names like "printLatestImages" or "LatestImages").

    The function printLatestImages() only includes an another function. The function printImageStatistic().
    Get to the file which the functions are included via SFTP.
    Duplicate both functions and rename it in the same file and near to the originals (below is a good place). Rename it unique, because a function getImageStatistic() is always available, but included not what you need.
    In this case you need not a "print" (echo), but a "get" (return).
    function getLatestImages_myname()
    function getImageStatistic_myname()
    Use the second in the first.
    Yet you can edit the function as you need.
    In this function is it a little bit complicated to change from "print" to "get". The simpler way is just to edit the part with "alt" and don't rename the function to "get". The better way is you change the first "echo" to a variable like "$returnvar =" and all other "$returnvar .=" and below the last echo make a "return $returnvar;".
    Yet you can use the function in your theme and change the string, which is returned by the function, before it is printed (echo) with PHP replace. Search a unique substring in the string and replace it.
    str_replace
    substr_replace
    preg_replace
    Use it like <?php echo str_replace('search', 'replace', getLatestImages_myname()); ?>

    In your case:
    <?php echo str_replace('" /></a>', ' free photo" /></a>', getLatestImages_myname()); ?>

    @acrylian , is here a little bit wrong with the quotations at the end?
    echo '<img src="' . html_encode(pathurlencode($image->getCustomImage($width, NULL, NULL, NULL, NULL, NULL, NULL, TRUE))) . '" width="' . $sizes[0] . '" height="' . $sizes[1] . '" alt="' . html_encode($image->getTitle()) . "\" /></a>\n";
    http://docs.zenphoto.org/source-function-printImageStatistic.html#578
    EDIT: OK, yet i understand it. The second alt quotation is slashed: \"
    "\" /></a>\n"

  • acrylian Administrator
    edited April 5

    Duplicate both functions and rename it in the same file and near to the originals (below is a good place). Rename it unique, because a function getImageStatistic() is always available, but included not what you need.

    Duplicate and rename yes, but don't place it in the same file! Never edit core or official files if you can avoid it. Better: Copy it to your theme's functions.php and use it there (don't forget to check for plugin dependencies though!).

    The "weird" mixture of single and double quotes is primarily because of the source code view only\n line break that only works with double quotes. (And yes it is a bit more weird than it needs to be ;-)).

Sign In or Register to comment.