Using WordPress inside of MODx

Well, this was a terrible implementation! 🙂  I wish that RSS feeds provided a more bandwidth friendly way to get information.

Please do not use the information from this post.  Instead, check out our WordPress Tools at http://allebrum.com/current_projects/allebrum-wordpress-tools-for-modx.  It was written for use in MODx so that is what the documentation targets, but it can be used anywhere.

WordPress (well, most blogs for that matter), do not make a good way to get some information.  So if you use Allebrum’s WordPress  Tools, please provide some feedback on ways that it can be improved so others can benefit.  Some calls seem to take a little while to process, but I guess that’s the nature of XML-RPC sometimes…..or Godaddy shared hosts, heh.  Not really sure which.  I should probably check into getting off a shared server at some point real soon!

This is not a complete solution!  It should get you started in the right direction.  I will probably add more to it in the future.

Step 1:  Log into your MODx manager and then browse to Elements>Manage Elements>Snippets>Add New Snippet.

Step 2: Add the following code into your snippet then save it as “WordPress”

<?php
$xmldoc = new DOMDocument();
$xmldoc->load($url);
$info = "";
$content = "";
foreach ($xmldoc->getElementsByTagName('item') as $feeditem){
  $info .= '<h2>'.$feeditem->getElementsByTagName('title')->item(0)->nodeValue.'</h2>';
  //$info .= '<h2>'.$feeditem->getElementsByTagName('description')->item(0)->nodeValue.'</h2>';
  $content = $feeditem->getElementsByTagName('encoded')->item(0)->nodeValue;
  $info .= $content;
}
return $info;
?>

Step 3: Create a new Resource and put the following code in there:

[[Wordpress? &url=`https://allebrum.wordpress.com/feed/`]]
Advertisements

2 Comments (+add yours?)

  1. Scott
    Oct 06, 2010 @ 07:20:48

    How can I set this to only pull in a certain number of of items? I have been able to mkae this do everything I need except to limit it to say 5 items.

  2. senica
    Oct 06, 2010 @ 07:39:45

    I guess you are using the WordPress Tools and not the script in this post.

    Are you wanting just a few title, or just a few posts? You can use the function getRecentPosts(int numberOfPosts) to get the most recent posts. There is an example how to use it here: http://allebrum.com/current_projects/allebrum-wordpress-tools-for-modx

    You might want to start reading at the top as the example usese $blog which is defined towards the top of the page.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: