Steffen Hi, the name's Steffen and I'm writing about the Web, programming and all those things coming to my mind. Enjoy your stay.

I'm currently working on fabidoo.com - 3D Printing for everyone!

Integrating zenphoto into WordPress

If you have a blog based on WordPress and you want to integrate zenphoto into that, you do that by creating a zenphoto theme that is based on your WordPress theme. I did that with my gallery and here’s a description on how I did that.

In the zenphoto installation directory, there’s a themes folder. Use one of these themes as a basis for your WordPress-like zenphoto theme by simply copying and renaming it and then activating it in zenphoto. A theme basically consists of its CSS, and the files index.php (the albumbs overview), album.php (an album with thumbnails), and image.php (for one single image). All these php files need to be touched in a similar way. I’ll explain it for index.php.

The first line in index.php is

<?php if (!defined('WEBPATH')) die(); ?>

Keep that one - never remove it. After that line, add the following one to import all WordPress functions (and replace “/blog/” in the URL with the installation directory of WordPress in your web root):

<?php require($_SERVER['DOCUMENT_ROOT'].'/blog/wp-blog-header.php'); ?>

After this line, we tell the WordPress theme to include the CSS of the zenphoto theme:

<?php
// add the zen css to the wordpress header
function addcss() {
  global $_zp_themeroot;
  echo '<link rel="stylesheet" href="'.$_zp_themeroot.'/zen.css" type="text/css" />';
}
add_action('wp_head', 'addcss');
?>

Now, remove all stuff from DOCTYPE to the “main” DIV and replace it by the header code of your blog:

<?php get_header(); ?>
...

Simply copy&paste all necessary code from your existing WordPress theme up to the beginning of the “content” DIV. Don’t include the “main-loop” part of the WordPress theme - but leave the “main” DIV of the zenphoto theme as it is.
After the “main” DIV is closed, close the WordPress “content” DIV and add the sidebar and the footer from your existing WordPress theme:

<?php get_sidebar(); ?>
<?php get_footer(); ?>

If you have WordPress and zenphoto use the same database on your machine, then your done. If not, you have to add two more lines to switch between the two databases you use. You do that by putting

<?php db_connect(); // reconnect to zenphoto db ?>

right before the beginning of the “main” DIV and

<?php $wpdb->select(DB_NAME); // reconnect wordpress db ?>

right after the end of the “main” DIV.

The final index.php of your new zenphoto theme will then look like:

<?php if (!defined('WEBPATH')) die(); ?>
<?php require($_SERVER['DOCUMENT_ROOT'].'/blog/wp-blog-header.php'); ?>

<?php
// add the zen css to the wordpress header
function addcss() {
  global $_zp_themeroot;
  echo '<link rel="stylesheet" href="'.$_zp_themeroot.'/zen.css" type="text/css" />';
}
add_action('wp_head', 'addcss');
?>

<?php get_header(); ?>
<?php db_connect(); // reconnect to zenphoto db ?>

<div id="content" class="narrowcolumn">
  <div id="main">
    put everything from the original zenphoto
    index.php "main" DIV here ...
  </div>
</div>

<?php $wpdb->select(DB_NAME); // reconnect wordpress db ?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Follow the same steps for album.php and image.php and you are done.

Tags: , ,

89 Responses to “Integrating zenphoto into WordPress”

< Prev 1 5 6 7 9 Next > Show All

  • 51
    Jadawin Says:

    Hello again… now it worked, don’t know how but now the sidebar goes left the content… just I guess I’ll have to fix some css to make it right… but there’s a bigger problem I think related to:

    because with IExplore it looks like header is completely messed up…. do you think is css problem or php problem?… Thanks in advance again! :)

    Ciao, Luigi

  • 52
    Alastair Mucklow Says:

    Hi… I’ve used this method of integration on Apache servers several times without any problems. However a friend of mine is using an IIS shared server, and the integration doesn’t work. I get this error message when trying to pull in the Wordpress functions:

    Warning: require() [function.require]: Unable to access \\n/wordpress/wp-blog-header.php in \\nas1.hosting.netcetera.co.uk\inetc710$\virtualservers68647\hand-embroidery.co.uk\NewWebsite\showcase\themes\handandlock\index.php on line 2

    Is this an IIS glitch or something to do with the server settings? Other non-integrated themes are working fine.

    Alastair

  • 53
    Alastair Mucklow Says:

    Hi again. It seems that IIS does not provide the environment variable DOCUMENT_ROOT, so the above integration method won’t work. UNLESS you do something to improvise. http://www.helicron.net/php/ suggests inserting the following code at the top of the script:

    However, this isn’t working for me - it’s a problem with the line that defines the $docroot variable. If I echo $docroot; I just get a blank screen. Can anyone unravel this for me? Would probably be useful to extend this integration for IIS users.

  • 54
    strangerpixel » Integrating Zenphoto with Wordpress on IIS Says:

    [...] integrating the two systems in order to implement your blog theme in your gallery or photo album. Ruzee’s method is the one I’ve been using. It’s a simple way of pulling your Wordpress functions into [...]

  • 55
    Dmitry Says:

    Hi Steffen,

    Very nice tutorial. But for some reason I’m having hard time to making it work.
    I’m using WP 2.1.3 and ZP 1.0.8

    After modifying all the pages, all I got is blank page…
    Any ideas on how to troubleshoot it?

    Thanks.

  • 56
    Dmitry Says:

    OK, today I have a bit of a progress…it’s not a blank page anymore…

    After uploading the modified files to the host, I’ve got this error:

    Fatal error: Cannot redeclare escape() (previously declared in /public_html/*******/artgallery/zen/functions-db.php:87)

    If I comment out escape function, then page will display fine.

    Any solutions?

  • 57
    ZenPhoto sorting hack : 徒然之書 The Void Notes Says:

    [...] 為什麼作者很忙 2. Zenphoto plugin for wordpress - ZenPress 3. Integrating ZenPhoto into WordPress 4. ZenPhoto not good enough? Flickr empire strikes [...]

  • 58
    Viitoria Says:

    Wow - great tutorial. Thank you!

  • 59
    Jeff U Says:

    Hi, I was wondering if anyone had any idea how to ‘fake’ this being a ‘page’ in wordpress… so things like is_page(’zenphoto’) would work in my wordpress theme? Any ideas?

  • 60
    tech.einaregilsson.com » Blog Archive » Integrating ZenPhoto into Wordpress Says:

    [...] ZenPhoto is a great image gallery written in php that I use on another page I have. It has a great admin interface and themes that are simple to use. I wanted to integrate it into a Wordpress blog so I looked around on the net and found a great article about it by a guy named Steffen Rusitschka. It explains how you can get your ZenPhoto gallery to look like your blog by including some Wordpress pages in your ZenPhoto theme. The article is at http://www.ruzee.com/blog/2006/06/integrating-zenphoto-into-wordpress/. [...]

  • < Prev 1 5 6 7 9 Next > Show All

    Leave a Reply

59101