ddhr.org
WordPress functions (2) Tuesday, Nov 29, 2005 10:26 am

For a while now, I've been trying to figure out how to use WordPress functions outside of the WordPress directory (i.e. in a different folder).  I just found a few posts about it on some WordPress Support pages (1, 2, 3, 4).  All you need to do is add this line of code to a PHP file:

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

After this statement is added, you can call any WordPress function.  For example, if you wanted to include WordPress headers and footers and the sidebar on a template in your Zenphoto installation, you would just need to include the file mentioned above and use the standard WordPress functions (get_header(), get_sidebar(), get_footer()). 

Note:  $_SERVER['DOCUMENT_ROOT'] is a call to your site's root directory (www.domain.com is the root of www.domain.com/blog/).  I'm not sure if it works everywhere, but it works for me. 

Linked:  Photo gallery

Pingback Wednesday, Jun 21, 2006 3:09 am
Dave Saturday, Nov 4, 2006 12:33 am

I encountered a problem with this when using the is_404() WordPress function outside the WordPress directory:  It was returning "true", meaning it thought it was encountering an error.  I think it has something to do with what Andy Skelton said about have_posts() and is_404() being mutually exclusive.  If there are no posts, it returns a 404 error.  I'm assuming this would also happen when the_loop isn't in use and/or if WordPress is used outside its main directory, which is the case in this instance.  The way around this is to create an exception:  Use some other method to identify a page outside of WordPress.  For example, in my case, I said if(basename(getcwd()) == 'pic') {do stuff} elseif(is_404()) {do other stuff}.  In other words, if the last part of the URL is 'pic', perform an action.  Otherwise, treat a 404 as a normal 404. 

The ZenPhoto support forums have some of the same information about integrating ZenPhoto with WordPress, but they suggest editing the main index.php file, whereas I edited each of the theme files (index.php, album.php, image.php).  My way works; I would assume theirs does as well.

Hello
Hi, my name is Dave Hosier, and this website is where I write my unfounded opinions on trivial matters. Feel free to look around, but please refrain from reading anything.

about | contact | feed

Comments (feed)
Dave on Wedding investment: Well obviously stay away from...
Rus on Wedding investment: Can you advise us on...
Someone who is not young but not old on Old age pains: Regarding Paragraph 1 Sentence 2,...
Bobby on Blackberry vs. black raspberry: I grew up in Olney,...
Richi near Frankfurt/M. on WinXP .mov thumbnails: Thanks Dude, that solved my...
saphrenne on Strummit From The Summit: I love this song so...
Rosalyne on Blackberry vs. black raspberry: I grew up eating BlackCaps...
BONNIE on Glitter cards: thats awsome... i laugh out...
Christy on WinXP .mov thumbnails: was skeptical at first... Windows...
Wendy on Tony Romo chokes: Have you seen this article...