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.
Hi, the name's Steffen and I'm writing about the Web, programming
and all those things coming to my mind. Enjoy your stay.
January 22nd, 2008 at 12:07
Hi, just wanted to say that was an interesting read. Great post!
February 6th, 2008 at 23:43
I have been a frequent visitor of this blog for some time now, so I thought it would be a good idea to leave you with my thanks.
Regards,
Jim Mirkalami
February 10th, 2008 at 11:03
[...] will run in parallel rather than in unison. So I continued searching the web until I stumbled on this article from Ruzee.com on how the author integrated ZP into his own [...]
February 13th, 2008 at 22:05
What happens when you want to include the Zenphoto Rss feed, as well as the javascript files that may be there?
February 29th, 2008 at 15:33
I like your blog theme. I want to use it on my blog.
Can you please tell me from where I can download these theme?
Many thanks
——————————————————————————–
Dan owner of the future gadgets blog future gadgets and inventions
March 11th, 2008 at 1:07
Thank you, thank you. Wonderful trick. Really works.
March 14th, 2008 at 6:13
thank you so much for this script, it integrates very well well with my page.
Im having a CSS issue though, its where the wordpress sidebar is displayed with the H2,H3,H4,H5 from zenphoto’s CSS and those seem the only css styles being ported to the sidebar. is there a way i can call up the wp theme CSS right before on your code?
thanks, and check out my site http://www.liveimagephoto.com zenphoto handles ALL images.
March 17th, 2008 at 23:58
sorry, forgot email. admin (at) liveimagephoto.com no spaces.
although i managed to fix my problem by just not calling up wp-footer at all on the zenphoto gallery pages. is there anything u can figure out by this information? apparently its something with closing the footer but still displays the internal css of ZP on external WP pages. perhaps after the /div needs a php endif?
March 21st, 2008 at 23:53
you shuld try using next gen gallery from wordpress website
March 24th, 2008 at 10:31
The next gen gallery will do ok…..
< Prev 1 … 7 8 9 Next > Show All
Leave a Reply