Well, for just for you-know-what-and giggles, I was able to pull up an essentially-unaltered Wordpress template from within MODx. The layout wasn’t perfect because I didn’t try to use all the WP code in MODx, but it was close.
In MODX, I created the following snippet, called wp_bridge :
<?php
if (!defined('MODX_WP'))
{
define('MODX_WP','MODX'); //MattC
/*
* Tells WordPress to load the WordPress theme and output it.
*/
define('WP_USE_THEMES', false);
/* Loads the WordPress Environment and Template */
if ( !isset($wp_did_header) )
{
$wp_did_header = true;
require_once( 'wordpress' . '/wp-load.php' );
}
}
?>
This allows us to not load the MODX bridge routine that will be set up in Wordpress. And vice versa (see below)
Next I created a new document template, the contents of which are
[!wp_bridge!]
[!wp_call!]
A snippet called wp_call is created and it looks like this :
<?php
get_header();
get_sidebar();
get_search_form();
get_footer();
?>
This snippet is invoking the basic Wordpress functions to get and process various templates. Just to see what would happen
In Wordpress, I have a file called modx_bridge.php which lives in whatever theme I am using. It is based on Tim Spencer’s work found here
http://timspencerweb.co.uk/blog/?p=3
There is another, similar, routine which can be found in the MODx archives which would probably work as well. But I haven’t tried it.
In any case, my version of that routine looks like this :
<?php
if (!defined('MODX_WP'))
{
// MODx integration
// -------------------------------------------------------------------------------
define('MODX_WP','WP');//MattC
// ----- CONFIG -----
define('MODX_SITE_BASE_URL', 'http://localhost/testsite/');
define('MODX_MANAGER_PATH', 'c:/xampp/htdocs/testsite/manager');
define('MODX_DOCUMENT_IDENTIFIER', 206); // The MODx document we are going to pretend to be
// ------------------
// Some defines used by the modx API
define('MODX_API_MODE', true); // Tells MODx index.php to not run $modx->executeParser
define('MODX_SITE_URL', (!isset($_SERVER['HTTPS']) || strtolower($_SERVER['HTTPS']) == 'off' ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].MODX_SITE_BASE_URL);
// Run the MODx config and get site settings
//$GLOBALS['database_type']='mysql';
require(MODX_MANAGER_PATH.'/../index.php');
$modx->getSettings();
// Set the docid (most sensibly to the MODx weblink to here) and get the MODx document object
$modx->documentObject = $modx->getDocumentObject('id', MODX_DOCUMENT_IDENTIFIER);
$modx->documentIdentifier = MODX_DOCUMENT_IDENTIFIER;
// Set the base URL for any MODx snippets
$modx->config['base_url'] = MODX_SITE_BASE_URL;
// Get AND parse a modx chunk. Cannot cope with nested snippets within the chunk.
function modx_chunk($chunk_name)
{
global $modx;
return $modx->rewriteURLs(str_replace('[~', MODX_SITE_URL.'[~', // Ensure that the link goes to the MODx site and not e.g. /blog/pagename
$modx->parseDocumentSource(str_replace('[!', '[[', str_replace('!]', ']]', $modx->getChunk($chunk_name))))));
}
}
?>
And it is included at the top of each Wordpress theme .PHP file like this
<?php require_once('modx_bridge.php'); ?>
With the variable "MODX_WP" available in both locations and MODx and WP functions available to the other app, I think it might be possible to have one set of layout and stylesheets for both apps. Not being intimately familiar with the innards of either MODx or WP, I wouldn’t be surprised if there is a ton of overhead that gets created, or that it is incredibly inefficient to do this. And there may be a lot of good reasons not to do this. But for the moment, ignorance is bliss. Or at least entertaining ...
UPDATE : I got two WP widgets to run in MODx...
Matt