Trying to use custom function in Wordpress

I'm trying to use the following function, which is stored in my zp-customfunctions.php file, in my Wordpress Footer.

`
function show_latest_image_links($number) {
$sql = "SELECT * FROM ". prefix("images") ." ORDER BY id DESC LIMIT $number";
$result = mysql_query($sql);
while($r = mysql_fetch_array($result)) {
$id=$r['albumid'];
$sql="SELECT * FROM ". prefix("albums") ." WHERE id = $id";
$album = mysql_query($sql);
$a = mysql_fetch_array($album);
echo '';
echo '';
$title=$r['title'];
echo $title;
echo '
';
echo '';
}
}
`
It works correctly, displaying text links to my latest photos, in my ZenPhoto footer. However, in Wordpress, I receive the following error.
Fatal error: Call to undefined function prefix() in /home/bryan/public_html/wp-content/themes/valid-light/zp-customfunctions.php on line 300

I have ZenPhoto pull in my Wordpress theme so that I can edit my ZenPhoto theme files from within Wordpress, etc. In my Wordpress header, I was able to successfully load zp-customfunctions.php using require_once. However, I haven't been able to use require_once to load my template-functions.php file from ZenPhoto. The following code:

`
define('ZENFOLDER', 'zp-core');
define('WEBPATH', 'gallery');
require_once(WEBPATH . "/" . ZENFOLDER . "/template-functions.php");
`
results in:
Zenphoto Error
MySQL Error: Zenphoto could not connect to the database server.Check your zp-config.php file for the correct host, user name, and password.Note that you may need to change the host from localhost if your web server uses a separate MySQL server, which is common in large shared hosting environments like Dreamhost and GoDaddy.Also make sure the server is running, if you control it.

My ZenPhoto installation is in the "gallery" folder in the root of my site.

"/" Wordpress is installed in the root
"/gallery" ZenPhotos is installed here

Is it possible to hard-code the path for template-functions.php, like this:

`require_once("http://www.bryanbrazil.com/gallery/zp-core/template-functions.php");`

It doesn't seem to work like this.

Hopefully I've provided enough details...thanks in advance for any help you can provide.

Comments

  • Oh yeah, Wordpress and Zenphoto are installed in the same database.
  • PHP includes/requires, etc. are on file system files, not URLs.
  • OK, so any idea why I get the Zenphoto Error when using the suggested require statement? Thanks!
  • What is failing is the user/password, etc. information for the database connection. Not really sure why this would be so, though. Possible some other Wordpress user can jump in here and help. I have no experience with it.
  • acrylian Administrator, Developer
    I just remembered this, was hard to find again (that is the disadvantage if no ticket is created...): http://www.zenphoto.org/support/topic.php?id=5723#post-33280
    Probably we should do what he suggests...
  • Hmm, I tried making the change to functions-db.php suggested by natenewz, but I couldn't get it to work. It looks like the end of the code isn't displaying properly in his post.

    If I can test anything out, just let me know. Thanks!
  • acrylian Administrator, Developer
    Besides that it is of course not recommended to hack core files, I guess you need to tell the script you posted at the beginning which mysql connection to use.
  • Don't worry, I backed up the file before modifying it and then restored the original when things didn't work. :-) I'm wondering if I have problems with multiple database connections because I use the Zenphoto Press plugin to display a random photo in my sidebar.
  • FYI -- I solved my problem by hardcoding the database prefixes and not using the prefix function. Still can't figure out why I can't require template-functions.php in my header, though.
Sign In or Register to comment.