ZenphotoCMS Forum
How to use customized data - Printable Version

+- ZenphotoCMS Forum (https://forum.zenphoto.org)
+-- Forum: Support (https://forum.zenphoto.org/forum-1.html)
+--- Forum: General support (https://forum.zenphoto.org/forum-4.html)
+--- Thread: How to use customized data (/thread-11289.html)

Pages: 1 2


How to use customized data - sbillard - 2013-08-23

You can also get the global parent album from any album by getUrAlbum($album_object)




How to use customized data - Papyrus - 2013-08-24

And with that useful call it's an even easier job. $variable = getUrAlbum($album_object). If $variable = photocards do this. If $variable = photobook do that. Cuts half the work of writing the function out.




How to use customized data - sbillard - 2013-08-24

Except that the function returns an object, so what you need is if ($variable->name = photocards)....




How to use customized data - tosca - 2013-08-24

Thanks everybody for helping.
I've succeeded in what I wanted to do: in the custom data field, I can enter as many name=value separated by a comma, and get them as an array in the program.

The only thing that remains to make it 'perfect' is transforming it into a function so I can use it in any other php page.




How to use customized data - tosca - 2013-08-24

@Papyrus: the purpose of using custom data or code block is precisely to avoid hard-coding. I didn't want either to make references to the album names or their parent.

With my solution, I have nothing to add/modify when I add a new album, or modify one that already exists. I can even add as many new variables as I want too, they will be automatically available in the program.




How to use customized data - acrylian - 2013-08-24

Good you managed it for your purpose! Many roads lead to Rome :-)




How to use customized data - tosca - 2013-08-24

Yes, once you know how to find your way! ;-)




How to use customized data - Papyrus - 2013-08-24

Well I'm very happy you worked it out. Always nice to see the different ways people tackle issues!

If it does help anyone in the future though, I whipped up my variant of the idea as a foundation. I'm sure many future visitors would appreciate any alternate methods you might be employing spelled out for them if you feel like it, tosca.

http://animepapers.org/software/zenphoto/code-snippets/multiple-layouts-dynamic-modification.html

Probably far from perfect, but if anybody needs a reference it's there with a tiny bit of documentation.

I'll also post here...and see how it comes out:

`

        echo '"'.getImageTitle().'"';

`




How to use customized data - acrylian - 2013-08-24

@Papyrus: Some quick comments:

  1. $masal = $_zp_current_album->getParent();
    getParent() returns an album object if there is a parent or NULL, so it is quite different to $theDecider;

  2. $theDecider = $_zp_current_album->getTitle();
    You should use the album name here. The title is never unique identifier especially since it changes on multilingual sites per language naturally.

  3. if ($theDecider = 'album-name-1')
    You mean of course == ;-)




How to use customized data - tosca - 2013-08-24

Here is the function I've written, but it is for retrieving custom data, whatever they are; in addition to custom thumbnails dimension, I've already used it to assign specific classes, and it could be used for anything else.

/* ** Récupération du contenu de "Données personnalisées" */ function mnaCustomData($page) { switch ($page) { case('album') : global $_zp_current_album; $custom_data = getAlbumCustomData(); break; case('image') : global $_zp_current_image; $custom_data = getImageCustomData(); break; case('page') : global $_zp_current_zenpage_page; $custom_data = getPageCustomData(); break; case('category') : global $_zp_current_category; $custom_data = getNewsCategoryCustomData(); break; case('news') : global $_zp_current_zenpage_news; $custom_data = getNewsCustomData(); break; } $data_array = explode(",",$custom_data); foreach ($data_array as $one_data) { $label_value = explode("=",$one_data); $custom_data_array[trim($label_value[0])] = trim($label_value[1]); } return $custom_data_array; }




How to use customized data - acrylian - 2013-08-24

That's actually more or less what I suggested above btw :-) What is $page in your context? Just asking since there is no "category" page.




How to use customized data - Papyrus - 2013-08-24

@acrylian Ah! Thanks for the tips, will help me going forward. I knew that title was a bad thing to call but just couldn't remember off the top of my head what else to use...and it worked so I shrugged it off. Corrections are always appreciated.

@tosca I see, a little different from what I pictured but useful for more than just many levels of image sizing. Looks nice. Thanks for contributing your code snippet too!




How to use customized data - tosca - 2013-08-24

$page allows to choose which custom data you want to get.
It works for album, image, page (as in Zenpage), category news, or news.
Unless I'm mistaken, getCustomData() exists for all these 5 objects.