Using WordPress in the Modx CMS
Modx does many things well. However, some things a better left to more specialized applications. In particular adding a blog to a Modx site is best done with WordPress. And, while I don't like WordPress as a CMS it works very well for blogs.
And, before I get 'flamed' by those using Jot for their blog, there are many things I like about Jot. We use it for comments on our articles. (See the comment section at the bottom of this article.) However, it doesn't have all the features available on a WordPress blog.
The biggest decision you need to make in integrating WordPress is actually a security issue. The easiest way to have the systems work together is by having them share a database. In general, I don't like to do that. It just gives the 'bad guys' another means of attack. However, in this case the benefits outweigh the risks. Having WordPress run in its own database would make it much harder to share data, which I wanted to be able to do.
The first step is to install WordPress. Download the latest version of WordPress and unpack it in its own subdirectory. Open that directory in a browser and follow the on-screen directions. WordPress is fairly easy to install so I won't go into it here.
Login as admin and go to the Plugins menu and activate Akismet. (Unless you like spam comments.) You will need to goto the WordPress website, open an account and get an activation number to finish the process. While you are on the WordPress site you may want to download and install the "All in One SEO Pack" from the Plugins list. While not necessary, it is a nice feature to have.
Skinning WordPress ranks right next to root canals on my list of 'Favorite Things'. Again, I am not going to go into it here. There is lots of information on the Internet on creating Themes for WordPress. I just 'hacked' the default Theme. It is not too pretty and there are some (OK - lots) unused classes -- but it works.
For a simple site there isn't anything more to do except add the link to your blog. However, I had one snippet that I needed to run in the blog. It was a small custom snippet that displays the affiliate ads in my sidebar. First, I created a sub-directory called 'modx' in the WordPress root directory to be used for Modx snippets that need to also work on the blog.
Getting the snippet to work was relatively simple. Here is how I did it:
- Create a file called snippet_name.php. The file name doesn't really matter but it does make life easier if names are consistent.
- The file contents look like this:
<php?
function snippet_name($variable) {
$output="";
<Paste snippet code here - rename the value returned by the snippet to $output>
return $output;
}
?>
- WordPress uses inline php so call the snippet with:
"<php? include_once('modx/snippet_name.php') echo snippet_name('my_variable'); ?>"
WordPress doesn't have access to the $modx object used in a lot of snippets. Since it does have access to the same database as Modx, you can substitute php calls to the database for $modx->query($rs). Pass variable to the function in the usual manner.
It should be possible to include the Modx "manager/includes/document.parser.inc.php" file and create a $modx object. However, I haven't tested that yet and it is beyond the scope of this article. Perhaps someone could leave a comment about that.
Compeek on Fri June 05, 2009, at 14:16:18 wrote