Keeping in mind that this is probably not very efficient (see OpenGeek’s comment here
http://modxcms.com/forums/index.php/topic,47741.0/topicseen.html ), this is the code used in this discussion
http://modxcms.com/forums/index.php/topic,44791.10/
NOTE : the responsiveness of the site referenced in that thread feels sluggish, so if I were going to try to do this again, I’d probably consider some of the other approaches mentioned. That said, this might give you some ideas, as I got MODx content showing up in WP and WP plugins running in MODx.
In a test install of Evo 1.0.2 with WP set up in a subfolder called "blog" I had
- this as the header in WP :
<?php require_once('modx_bridge.php'); ?>
<?php
/**
* @package WordPress
* @subpackage Classic_Theme
*/
?>
<?php if (MODX_WP == 'WP') { echo modx_chunk('minimal_header1'); } ?>
<link rel="pingback" href="<?php bloginfo('pingback_url'); ?>" />
<?php wp_get_archives('type=monthly&format=link'); ?>
<?php //comments_popup_script(); // off by default ?>
<?php wp_head(); ?>
<?php if (MODX_WP == 'WP') { echo modx_chunk('minimal_header2'); } ?>
<div id="rap">
<!--<h1 id="header"><a href="<?php bloginfo('url'); ?>/"><?php bloginfo('name'); ?></a></h1>-->
<div id="content">
<?php if (MODX_WP == 'WP') { echo modx_chunk('test_modx_chunk'); } ?>
<!-- end header -->
- this as the footer in WP :
<?php require_once('modx_bridge.php'); ?>
<?php
/**
* @package WordPress
* @subpackage Classic_Theme
*/
?>
</div>
<?php get_sidebar(); ?>
<p class="credit"><!--<?php echo get_num_queries(); ?> queries. <?php timer_stop(1); ?> seconds. --> <cite><?php echo sprintf(__("Powered by <a href='http://wordpress.org/' title='%s'><strong>WordPress</strong></a>"), __("Powered by WordPress, state-of-the-art semantic personal publishing platform.")); ?></cite></p>
<?php if (MODX_WP == 'WP') { echo modx_chunk('minimal_footer'); } ?>
</div>
<?php wp_footer(); ?>
<?php if (MODX_WP == 'WP') { echo modx_chunk('minimal_end'); } ?>
- this in "modx_bridge.php", from Tim Spencer’s work here
http://timspencerweb.co.uk/blog/?p=3%29" target="_blank" rel="nofollow">http://timspencerweb.co.uk/blog/?p=3%20%28
http://timspencerweb.co.uk/blog/?p=3%29
<?php
if (!defined('MODX_WP'))
{
// MODx integration
// -------------------------------------------------------------------------------
define('MODX_WP','WP');//MattC
// ----- CONFIG -----
define('MODX_SITE_BASE_URL', 'http://www.website.url/'); //needs a trailing slash
define('MODX_MANAGER_PATH', '/home1/path_to_modx_manager'); //no trailing slash
define('MODX_DOCUMENT_IDENTIFIER', 2); // 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))))));
}
function modx_snippet($snippet_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->runSnippet($snippet_name))))));
}
}
?>
- in MODx, "minimal_header1" looks like this :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>[(site_name)] | [*pagetitle*]</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="[(base_url)]assets/templates/default/site.css" type="text/css" media="screen" />
<base href="[(site_url)]" />
<!--[if lte IE 6]>
<style type="text/css" media="screen, tv, projection">
body { behavior: url(assets/js/csshover3.htc); } /* hover:anything support */
#content { margin-left: 22px; } /* to avoid the BMH */
a, a:link { border-bottom-style: solid } /* becuase IE just doesn't dot */
</style>
<script type="text/javascript" src="assets/js/sleight.js"></script>
<![endif]-->
- in MODx, "minimal_header2" looks like this
</head>
<body>
<div id="page">
<div id="header">
<div id="search"><a name="search"></a>
<!-- if you wanted a site search, this would be a good place -->
Blog name : [!wp_bloginfo? &id=`name` !]
</div>
<h1><a href="[~[(site_start)]~]" title="[(site_name)]">[(site_name)]</a></h1>
</div>
... etc, etc. for the footer.
The MODX_WP flag was my attempt at trying to streamline some logic. In hindsight, the logic test just unnecessarily adds to overhead, I imagine.
And for some reason that I can’t recall, my wp_bloginfo snippet isn’t working correctly. I was probably messing around with it, started on another project and never tidied it up.
Matt