How to print the outcome of getTags()

Now I have

`
$listoftags = getTags();
echo $listoftags;
`
but that only returns 'Array'.
How can I print a list, seperated by comma's, of $listoftags?
«1

Comments

  • By the way, I know of the function printAllTagsAs, but I don't want to print ALL tags, just a list of tags used in a certain album.
  • acrylian Administrator, Developer
    Sometimes looking at the documentation really helps:
    http://www.zenphoto.org/documentation/functions/_template-functions.php.html#functionprintTags
    There is nearly always a get/print pair of functions.

    Do you know what an array is? If not I suggest to learn the php basics. To print an array you need to loop through it. For a one dimensional array like this one: http://www.php.net/manual/en/control-structures.foreach.php
    Infos on array: http://php.net/manual/de/language.types.array.php
  • I know what an array is, but don't really know how to use it.
    I read the instructions on printTags, but it somehow illudes me.

    On a page with thumbs I would like the list of tags to appear (tags associated with images inside that album) In album.php I have this:

    `
    $listoftags = getTags();
    printTags('links',NULL,'taglist',', ',TRUE,'',true);
    printTags($listoftags);
    `
    but both the second and third line result in 'no tags' message, while some of the images inside this album do have tags.
  • acrylian Administrator, Developer
    You should really read the doc carefully. `printTags()` prints the tags of the current album or image. It depends in which context you use it. I admit that not directly written there. But take a look how the standard themes use that function.

    You can't pass an array (the doc does not tell you that at all...). So on album.php or within the next_album loop it will print the album tagsg and on image.php or within the next_image loop it will print the image tags. (it will also print tags for Zenpage pages or news articles btw if used in that context).

    So you only need your 2nd line but in the right context.
  • So if I understand you correctly, what I want is not possible, because I want the tags of all the seperate images within an album displayed on the page with the thumbs (within album.php). That would make sense to me because then, inside an album with the title 'mammals' I could quickly jump to 'dogs' or 'german' or 'sheppard'.

    It would be nice if this was possible in the future.

    Thanks for your information though :).
  • acrylian Administrator, Developer
    I probably do not understand. So do you want to display all tags of all images within that album or the tags for each image in that album? The last is possible if you use the function within the next_image loop.

    The first is possible too but requires custom coding. I have something like that on my list though but it's not the only one..;-)
  • The tags for each image in an album is what I would like, so I would have to look into the next_image loop. I'll do that, and hopefully get it to work ;). Thanks.
  • acrylian Administrator, Developer
    Then just add the printTags() within that. Of course some CSS styling of the list will be required.
  • Uh... sorry, but are the two options you mentioned not exactly the same???
    After reading your reply again I think what I want is option 1 and not option 2 as I mentioned in my previous reply.

    So: all tags for all images inside that album in one list beneath or aside from the thumbs.
  • acrylian Administrator, Developer
    No.
    1. Would collect all tags of all images in the album and display them as one list. (not possible without coding).
    2. Prints the tags for each image individually.
  • Well, option 1 is what I wanted. So I'll have to be patient I guess, until the idea gets out of your mind and into a future release of ZP :(.
  • acrylian Administrator, Developer
    Yes, sorry. (Or if you really badly need it you could also "sponsor" that feature/plugin.).
  • acrylian Administrator, Developer
    Well, I figured I would like to have this function, too. So I indeed started on a plugin. Not sure if that will become an official one but I will make it surely available somehow.
  • acrylian Administrator, Developer
    You might want to test the new plugin "tags_from_album" in tonight's nightly.
  • Hello Acrylian,

    I just tried the plugin, but somehow I'm not getting any results.
    First I tried this:

    `printAllTagsFromAlbum("",false,'images','',"",false,1,1,1,50)`

    as I expected the function to automatically return the tags from the images within the current album. But with this I get:

    `
    `
    No link, no text.

    Then I tried

    `printAllTagsFromAlbum("cows",false,'images','',"",false,1,1,1,50)`

    but with the same result. Perhaps I'm doing something wrong. It would be nice if the function could return a taglist of a specified album > images, but in general I think it should return the tags from the current album > images.

    But like I said, perhaps I'm not using the function correctly.

    EDIT: I placed the function in album.php...
  • acrylian Administrator, Developer
    The first does not work, this function requires an album to be set.

    Is "cows" a subalbum? Subalbum names are not the direct folder name but the path including parentlevels: `toplevelalbum/sublevelalbum/...`. The easiest to get the right name is to use `$_zp_current_album->name` if you are in album context. Otherwise you need to remember that manually.
  • Ok, so now I did this:
    `printAllTagsFromAlbum($_zp_current_album->name,false,'images','',"",false,1,1,1,50)`

    but still the same (no) results and the same empty html output.
  • acrylian Administrator, Developer
    Are you really sure that the images in that album have tags and that you are in album context??? Are there really direct images in that album you are trying? If not the 2nd parameter needs to be "true". Or any errors in the server log maybe?

    (I have of course tried it and it did work...)
  • You can take a look at this album: cows.

    The first four pictures I gave tags. Underneath the thumbs I placed the code

    `printAllTagsFromAlbum($_zp_current_album->name,false,'images','',"",false,1,1,1,50)`
  • acrylian Administrator, Developer
    I wonder why it worked for me. Anyway, will try to reproduce and solve it. Thanks for testing.
  • acrylian Administrator, Developer
    I fear I can't reproduce it. Neither on my local MAMP install nor on my live test site. See here working as expected: http://zenphoto.maltem.de/album1
    Called with `printAllTagsFromAlbum($_zp_current_album->name,false,"images");` right before the description call and the next_image loop.

    There must be something different. Maybe you can try a standard theme?
  • That's weird, because I tried exactly your code in album.php of the default theme at three places and get the same results as before: nothing :(.
  • Correction... I get only the numbers within the default theme and no valid link or name:

    ` (130)`
  • acrylian Administrator, Developer
    Indeed weird. Maybe it's a MySQL issue. Which version do you have? I have only tested with MySQL 5.1.37 (locally) and MySQl 5.0.51.a (live test).
  • PHP Version 5.2.10
    MYSQL 4.1.22
  • acrylian Administrator, Developer
    I guess the MySQL version might then be the cause of this althought I think this should actuall work with 4. But I wonder why there is no error message then...

    Could you maybe upgrade to MySQL 5? We recommend that anyway...
  • I'll have to ask my provider if he can do this for me. I'll let you know the result.
  • acrylian Administrator, Developer
    Ok, mine lets me switch it myself on its admin backend.
  • acrylian Administrator, Developer
    I did some investigation and found out that the query I originally adapted indeed did not work exactly as expected. So I reworked it. The change will be in tonight's nightly. Please give it a try, it should really not require MySQL 5.
  • Using the code underneath, I still get only numbers in the default theme and nothing in my own theme.

    `
    <?php

    echo "Trefwoorden in dit album: ";

    printAllTagsFromAlbum($_zp_current_album->name,false,"images","","",false,1,1,1,50)

    ?>
    `
Sign In or Register to comment.