ddhr.org | 2005 | 11 | 29 about | archives | comments | rss

WordPress functions (2) Tue, Nov 29, 2005
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. #technology

Comments:
pages ending in .php + wordpress « WordPress Support Wed, Jun 21, 2006
[...] I searched for this a while ago and found several things in the WordPress support pages: 1, 2, 3, 4, ddhr.org/2005/11/29/wordpress-functions/  Posted: 2006-03-15 17:46:41 # [...]

Dave Sat, Nov 04, 2006
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.


← older post 314 of 3123 newer →