• 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?

Viewing 3 replies - 1 through 3 (of 3 total)
  • I’m not good enough at PHP to understand what *exactly* is going on.

    BUT, I was in the same type of situation as you are the other day. Click here to see the post – I also posted my solution and where I found it.

    But basically, I had created a PHP-based email form that I couldn’t get WordPress to recognize when I slapped it into the template. Couldn’t get it to work – until I finally figured it out with what I put in that post

    Maybe my solution will work for you? Hope so!

    Thread Starter thegreyorm

    (@thegreyorm)

    Thanks for the info, doodlebee. I tried your solution, because I had attempted something similar myself earlier but wanted to integrate the gallery as a page (and understand the php better).

    I did find out something interesting, though: apparently, the header call itself is what is causing problems.

    If I put this:

    <?php
    define('WP_USE_THEMES', false);
    require('./wp-blog-header.php');
    get_header();
    ?>

    in my page, it causes something to break, and the php variable doesn’t pass back to the page. However, if I remove that and leave everything else, the page passes the variable.

    Does anyone know why this is?

    “it causes something to break”

    Is there any error message, or something?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Trying to pass variables with PHP in template’ is closed to new replies.