Trying to pass variables with PHP in template
-
A few years back I wrote a quick-and-dirty art gallery script for my website, way before I had ever heard of WordPress. I upgraded my blog to WP this past year, and I want to include my gallery as a seperate page inside WP.
I’ve included the PHP and such inside a new template, have coded a seperate sidebar for the page so that users can switch between sections, and everything works fine EXCEPT for the fact that I can not change the gallery I am looking at.
You can see the page here: Gallery
The “Galleries” links on the left hand side are what I am having trouble with. The links works fine outside of the WP template, but I can’t figure out how to get WP to recognize that I am using the link to pass a new variable to the page (that variable defines which images appear, based on the gallery they have been identified with, as well as the text at the top of the page).
This is the relevant code in the page.
<?PHP//set category to gallery if no category given
if (!$catid) {$catid = 'Gallery'; }?>
The above checks the variable $catid, and sets it to the main gallery if the variable is empty. The code below is from the sidebar; each link sets the $catid variable when the link is clicked so the page loads only the images from the chosen gallery.
<a href="<?PHP print("?page_id=94&catid=Gallery"); ?>" >Main Gallery</a>
<a href="<?PHP print("?page_id=94&catid=Sorcerer"); ?>" >Sorcerer Gallery</a>
<a href="<?PHP print("?page_id=94&catid=published"); ?>" >Published Illos</a>
<a href="<?PHP print("?page_id=94&catid=abstract"); ?>" >Abstracts</a>
I know the code itself is fine because it has worked just fine for years, but obviously the variable-passing code isn’t working once dropped into a WP template. Also, the template is apparently picking up the initial command that sets the variable to the main gallery (because if it was not, nothing would be showing up).
My problem is that I don’t understand the architecture of WordPress well enough to understand why it isn’t working, why it is working the way it is, or how to make what I am attempting to do work.
Can anyone help?
- The topic ‘Trying to pass variables with PHP in template’ is closed to new replies.