HowTo – Integrating WordPress Features Into Other Programs

Filed under: Wordpress Tips

wordpress-logoAlthough WordPress has a number of great internal features and the ability to be extended through plugins there are times when using supplementary  software can make the management of your site so much easier.

Unfortunately when you install a new piece of website software you are faced with the decision of either theming it to match the layout of your main WordPress site or making it look different so users know they are on a different section of your site.

It is a difficult choice and you are likely to endup losing access to some of the features in WordPress that you want to include.

The work around is to load a connection between WordPress and your external ap by including your wp-blog-header.php file at the top of your other applications main file or header file.

Once loaded in your external ap you will have access to all the functions available in WordPress.

This means if you include a menu or a sidebar showing your recent posts and then make changes or additions in your WordPress site the changes will show in your external Ap.

HOWEVER you will need to make sure your CSS is being used correctly and this could be a problem if you are using images that depend on /relative/directory/structures… replace them with http:// calls where necessary.

Now as to not be confused this is different then loading your header.php file that is found in your theme folder. The wp-blog-header.php file can be thought of a startup command for WordPress to begin executing and your theme file header.php is the portion of your theme that generates the top section of html such as your title and menu area.

Loading The Header

The wp-blog-header.php file should be located in your root directory if you are using WordPress 3.0 or higher or it may be in a subdirectory where your wp-config.php file is.

To load the file use a basic PHP require or include call

[php][/php]

<?php require(‘/dir/wp-blog-header.php’); ?>

[php][/php]

If you decide to use an include statement instead of a require statement your external ap will continue executing after a failure of loading the WordPress header file. This can be a good or bad thing depending on your hosting environment and is something you should investigate as a basic PHP code writer it won’t have effect on the connection between the two aps.

Making Use Of The Connection

Once you have connected both of your applications you will need to do some trouble shooting just incase some of the functions in WordPress are duplicated in your outside ap. This should not really be a problem but if necessary you may need to use a file based text string replace to rename functions and their calls in your outside ap. I suggest Active State Komodo Edit that can find and replace inside files in a directory and all its subdirectories.

Now you can include any WordPress feature the same way you would in your Theme file.

You can call dynamic sidebars or display a loop full of posts or titles of posts.

You will also have access for checking if a user is logged in as a member of your WordPress Site by using conditional statements.

Basically any feature that you are useto using within your main WordPress site will be available to you.

Real World Examples

Integrating WordPress in this way is best when your external application can not be fed into WordPress by the use of a Custom Page Theme file.¬† If you don’t know what I mean you should take a look at designing a custom page template and the ability to include php inside the page template.

Larger applications such as a form where users can add content phpBB is one or a shopping cart application require dedicated management and many of the features just can not be duplicated with a plugin.

For instance if you run a clothing consignment store your inventory may be scanned into either your shopping cart or a spreadsheet file that you import into your shopping cart.

Managing hundreds or thousands of items from within a WordPress shopping cart plugin is not reasonable because you can not quickly manage your online purchases and inventory. You will also be limited in other ways such as the ability to quickly generate checkout links to paypal that bounce back to a specific url for file downloads or the ability to manage coupons and dozens of other features that a full shopping cart can offer.

This is not to say the WordPress shopping cart plugins are bad its to say if you have a large store and you have to depend on it for your main business and you have to integrate your shop with your tax preparation software it can get rather complex.

Additionally when you are managing thousands of form posts a day and you need to keep that content separate from your main site adding a phpbb install vs letting visitors join your site as Authors will reduce your headaches. Not to mention some banner advertisers restrict placement on content that is not managed.

The one drawback of using external aps is that your visitor will most likely need to login twice if they are also a member of your WordPress site when they want to process an order from your store or access your Form area.