Hi All,
I was wondering if it was possible (and if so, how?) to pass a parameter (for example a category id or photo id) into a page added using Additional Pages?
Thanks.
Piwigo version: 2.9.4
PHP version: 7.0.30
MySQL version: Ver 15.1 Distrib 10.1.26-MariaDB
Offline
Hi :-)
what do you want to do exactly?
Offline
Hi ddtddt
I have a page listing the root categories of my site and showing the last 5 added images. I'd like a link for each category that would take the user to a new page that shows more of the recent images for the selected category and maybe even page through the rest of the images in the category and it's children.
Offline
Hi :-)
Have you test [extension by plg] PWG Stuffs
Offline
Thanks for the suggestion.
I've had a look and while it does do some of the things, it's a bit limited. I can't see any way to put a block on it's own page (for example) and it doesn't allow paging through more images in a category (for example if I'm showing the last twenty of a particular category, there's no way to add a link to see 21 to 40).
Offline
Hi :-)
you can see code and make personal plugin
Offline
I assume it's okay to answer my own question here, and hopefully someone else will find this useful later.
So rather than try and pull apart PWG Stuffs, I took a different approach more akin to my original request.
I added the following to my Personal Plugins:
add_event_handler('AP_render_content', 'addUrlTokens'); function addUrlTokens($content) { global $tokens; $data = '<script type="text/javascript">var tokens = {}; '; if ((isset($tokens)) && (count($tokens) > 0)) { for ($i=0; $i < count($tokens); $i+=2) { if (isset($tokens[$i+1])) { $data .= "tokens['" . $tokens[$i] . "'] = '" . $tokens[$i+1] . "';"; } } } $data .= '</script>'; return $data . $content; }
This takes all the tokens from the URL and creates them as a javascript hash at the start of Additional Page's pages called tokens. So you'll end up with something like this at the top of your content:
<script type="text/javascript">var tokens = {}; tokens['page'] = 'test2';tokens['wibble'] = 'cli';</script><style type="text/css">
In this example, the URL used was "index.php?/page/test2/wibble/cli"
You can then use it in your javascript, something like:
<div class="d-flex justify-content-center"> <div id="data" class="mt-2"></div> </div> <script type="text/javascript"> Object.keys(tokens).forEach(function (key) { var value = tokens[key] $('#data').append('<div>' + key + ' = ' + value + '</div>'); }); </script>
Obviously you don't need to iterate the array, but do remember to check the key exists before attempting to use it.
Edit: Obviously this won't work with stand-alone pages, but then you probably have access to the URL parameters using more standard methods.
Last edited by Undergrid (2019-03-16 23:02:32)
Offline