Prior to upgrading my site and making it more code efficient, I always had a problem of integrating WordPress and Gallery together seamlessly and call functions from each program without any conflicts. By nature, unlike gallery 2 (G2), gallery 1 do not have a naive system in support for templates – sticking to html “wrappers” which you can add custom code to as the name suggest, wrap your site’s HTML code around the gallery so that it appears integrated with your current site layout.

So why use an older version of gallery (G1) instead of the newer G2? There are many advantages of using Gallery1 instead of the database driven gallery2, namely because of the avoidance of large dependence of databases and slow loading of pages gallery 2 have on my site compared to 1.

Given this issue, previously all my WordPress WordPress functions within my photo gallery pages are called out through various strategically located and placed iframes, though cross-browser safe, it’s not the ideal way to display content. Ideally, all content should be rendered and shown on a single page with minimal redundant frames which can possibility slow down load timings and opens up more areas of inconsistently which could be avoided in the first place.

This issue is widely raised in both the WordPress and gallery forums but with little avail, with even veteran users there concluding:

“if someone figures out how to include the wp functions inside the Gallery wrappers, lemme know.”

I decided to look into the integration issue (again), also as part of my the scheduled site revamp and attempts to solve the problem. A Google gave me a possible solution as highlight by Ron on his blog:

Overall, I’ve been happy with WordPress. However, there was one large bug I was never able to squash: it didn’t want to play well with Gallery. For some reason, I was never able to call WordPress functions from within the photo gallery pages. I wanted to make these function calls in order to have the side bar menu (which contains recent posts, comments, and other WordPress data) remain consistent on all the pages.

A simple server-side include should have taken care of this, but it never worked…

What he meant was including the WordPress functions “blog-header.php” right in the gallery header/footer wrapper template files using a server-side include should solve the problem. However, that will never work even if the included file and path are correct, the functions will never be able to be called.

Ron solution then came about with including the functions right into the gallery core file itself (util.php) with the following code added right at the top of the file:

< ?php require_once('../path/to/wp-config.php'); ?>

Which worked for him, presumably be that he is running Gallery 1 with WordPress 1.2 and below (that was a dated blog post by Ron too).

For me doing that will give me a “gallery has not been configured” error page, which apparently is a big problem highlighted by few who gave feedback on Ron’s blog post as well, but not addressed till now too. Going further into the topic it goes to show that this problem is only evident for all versions of Gallery1 to present and versions of WordPress 2.0 and below. I am running WordPress 1.5.

Dissecting the code, it seems that including the WordPress headers in the util.php files do allow you to call functions within all gallery pages, but a conflict due to common configuration paths to each program confuses gallery with the WordPress config directory, therefore being unable to find it’s own configurations and thus reverting to it’s “unconfigured state”.

So the final solution is a simple fix to tell both WordPress and gallery what directories do they belong to, this is done but manually defining the GALLERY_CONFDIR and ABSPATH variables for each. Add these following code to your util.php located in your gallery root folder depending on where your WordPress and Gallery installations are.

< ?php include_once("../blogs/wp-blog-header.php"); define('GALLERY_CONFDIR', '../gallery'.'/'); define('ABSPATH', '../blogs'.'/'); define(dirname(__FILE__), '../gallery'.'/'); ?>

And the problem will be solved! In the example, I have my WordPress install in a “/blogs” folder from the root, similarly, the Gallery install takes a “/gallery” folder from the root, please change the code paths to suit your install.

Remember to paste that code into any new install of gallery 1 as util.php will be overwritten with each new install.

LEAVE A REPLY

Please enter your comment!
Please enter your name here