Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieving querystring parameters
#1
I'm sure this is covered somewhere in here, but I haven't been able to track it down...

I want to make a single page to display any gallery, and just pass it the name of the gallery in the URL. I've made a page template for this in my theme, and an empty page using it. The template picks up the parameter as $_REQUEST['galname'] and that part works - parameter does get to the page. But the gallery generation doesn't work - I just see the string which is meant to trigger it. I'm guessing this is because this substitution is happening too late in the process of building the page. So, is this even possible? Any pointers welcome if it is.
Reply
#2
Hi,

Quote:I want to make a single page to display any gallery,

- Ok this is easy enough

Quote:I've made a page template for this in my theme, and an empty page using it.

- Yes using an empty page for this works (similar working concept "anything is a page")

Quote:I just see the string which is meant to trigger it.

If the string is a hook or a call it just should work. Maybe the needed js and css
for the gallery does not get loaded ? Did you check the console output in your browser ?

Tip: you could make a shortcut and use one of the powerful plugins of Mvlcek or Bigin
to setup such a single page to display a gallery.

But of course the GS api is alreay more than flexible enough to hand code this by your own.
For more support we need to see the template you made for it and the code running in it.
Reply
#3
Thanks for the response.  I have attached the template page from my theme. You will see that down where the page content is fetched, there is a fixed string which gets the passed querystring parameter injected into it. This is intended to invoke my own plugin (MAgallery) to generate the gallery. But it doesn't. The page appears, showing the (%....%) string exactly as it is constructed. It seems like the plugin is not being invoked.

The attached version of the page does not have the get_page_content() call, but then thought that's where plugins must be invoked, so I have since added it back on the line after the (%...%) string, but it still doesn't work either way. It feels to me like I am doing this at the wrong point in the page construction process, but I can't imagine where else to do it (not strong on GS internals).


Attached Files
.php   gallerypage.php (Size: 1.87 KB / Downloads: 1)
Reply
#4
I have achieved my objective. Instead of in the template, I have added a couple of lines in the PHP code of my gallery plugin, and it now retrieves the querystring parameter, if required. So I don't need a special template at all. And in fact it's now more versatile than I originally wanted.

So now if my page contains a string like this:

(% MAgallery gal=galleryname %)

then the plugin will go to the filesystem and get the data for the gallery named "galleryname", and render the required content. But if the string is like this:

(% MAgallery gal=@galname %)

then the plugin will retrieve the value of $_REQUEST['galname'] and use that as the gallery name to find and render. All seems to work fine, and I'm very pleased with the result. And when I think about it, it seems to me that the plugin is logically where this code belongs.
Reply
#5
Just another recommendation. The plugin Purl allows to retrieve all parts of URL, including anchor, host, etc.

It can be used with or without jQuery.

Usage is very simple and cool:

var url = $.url('http://allmarkedup.com/folder/dir/index.html?item=value'); // jQuery version
var url = purl('http://allmarkedup.com/folder/dir/index.html?item=value'); // plain JS version
url.attr('protocol'); // returns 'http'
url.attr('path'); // returns '/folder/dir/index.html'
However, as of Nov 11, 2014, Purl is no longer maintained and the author recommends using URI.js instead. The jQuery plugin is different in that it focuses on elements - for usage with strings, just use URI directly, with or without jQuery. Similar code would look as such, fuller docs here:

var url = new URI('http://allmarkedup.com/folder/dir/index.html?item=value'); // plain JS version
url.protocol(); // returns 'http'
url.path(); // returns '/folder/dir/index.html'

https://www.downloadtexasgisdata.com/dow...ounty-gis/
https://www.downloadtexasgisdata.com/dow...ounty-gis/
Reply




Users browsing this thread: 1 Guest(s)