Technical Tips on Connecting WordPress Functions to Web 1.0 Sites

I’ve just read a great post by Marty Weintraub over at AimClear, where he describes how to bolt on a copy of WordPress to your old Web 1.0. site to bring it up to date. This is something we have often done here at e3internet but I wanted to expand a little on this point he made and join in the conversation:

7 Grab content from the WP database (recent headlines, stories, etc… and display it on any page in the legacy site.

Unless you have a programmer on hand I can see some of you looking at this and wondering how it’s done. For this post, I’ll outline a couple of technical tips on achieving this with some basic HTML knowledge.

Note: The following techniques will only work if the Web 1.0. page you are running this on is also a .php page. Please backup any pages before trying these out. See the disclaimer.

1. Including the Header Link

When you copy over functionality, such as your latest blog posts you will need to also copy in the link to the wp-blog-header.php file in your WordPress installation directory. This “hooks up” the function to the WordPress core and allows it to work. As an example, lets take the post archives output:


<h2>Archives</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>

So all we would have to do here is make sure that above this code we place a link to our copy of wp-blog-header.php:


<?php require($_SERVER['DOCUMENT_ROOT']."/path-to/wp-blog-header.php"); ?>
<h2>Archives</h2>
<ul>
<?php wp_get_archives('type=monthly'); ?>
</ul>

What I have done here is tell my new page how to find the wp-blog-header.php file but writing in the path from root. You will have to change the code here for /path-to/ to reflect your setup. While you could replace $_SERVER['DOCUMENT_ROOT'] with the full path (i.e. on cpanel /home/username/public_html/) this method prevents you ever having to make code changes should you move servers.

2. Showing Your Latest Posts

Now this is the functionality we most often carry across to our old Web 1.0. sites. This will allow your users to read your latest news as well as providing some fresh front page links for the robots to follow, helping to rank these new articles faster.

I always recommend using the Customizable Post Listings Plugin by Coffee2code. The reason for this is that you can easily control the display of the posts, especially the character length of the post description. It is well worth reading Lorelle’s write up of the plugin to get an idea of what you can achieve.

As before, we would simply install the plugin and use one of their hooks plus our path to wp-blog-header.php


<?php require($_SERVER['DOCUMENT_ROOT']."/path-to/wp-blog-header.php"); ?>
<h2>Recent News</h2>
<ul>
<? php c2c_get_recent_posts(10); ?>
</ul>

AHHH It’s broken my site!

OK, if you’re unlucky this can sometimes happen, and the reason you need to test your site extensively after copying across any WordPress functionality. In non-techie speak, this is because functions we call from WordPress conflict with ones you are already using in your current CMS. Not to worry though, there is still options you can use before calling in the programmers.

3. Magpie RSS Parser

In cases where I have wanted to show the latest posts but have had trouble with code clashes, the Magpie RSS parser often saves the day.

The first thing to do is to download the Magpie directory, unpack it and upload this to your web site. Put this into the root folder, and rename the whole folder ‘magpie’ to keep things simple (not magpierss-0.72 or similar).

Now we need to put some code on our Web 1.0. site to show the recent posts. There are many configuration options with Magpie and I would recommend joining the mailing list for support but this will start you off.


<?php
require_once($_SERVER['DOCUMENT_ROOT']."/path-to/magpie/rss_fetch.inc");
$num_items = 3;
$rss = fetch_rss('http://www.my-wordpress-feed-address');
$items = array_slice($rss->items, 0, $num_items);
foreach ( $items as $item ) {
$href = $item['link'];
$title = $item['title'];
$desc = $item['description'];
$cat = $item['category'];
$date = date('M j\, Y', $item['date_timestamp']);
echo '<h4><a href="'.$href.'">'.$title.'</a></h4>';
echo '<p>'.$desc.'.<a href="'.$href.'">more</a></p>';
}
?>

Now to explain this code.


require_once($_SERVER['DOCUMENT_ROOT']."/path-to/magpie/rss_fetch.inc");

Again, here we write in the path to the new magpie directory and the file rss_fetch.inc. If this was located in http://www.mydomain.com/magpie/rss_fetch.inc you would copy the line above, if your magpie directory is located elsewhere, adjust accordingly.


$num_items = 3;

Pretty self explanatory, here you put in the number of items on the RSS feed you want to show.


$rss = fetch_rss('http://www.my-wordpress-feed-address');

Here we put in the URL of the RSS feed we want to display. Usually this would be the posts feed but you can play around with the various options. Maybe you want to display your comments feed or just one category of WordPress. You can even use this method to display the RSS feeds from other social media the company is involved in, like Twitter or Flickr.

If you are using this code on an e-commerce web site, with SSL enabled then remember you should change the http to https, so that users are not sent warning messages when entering a secure area.

The rest of this code will display the post titles (as URLs) and the description. Now the one problem with Magpie is that there is no way to control the length of the description (AFAIK). This can be a problem as large descriptions can sometimes cause design issues when pressed for space on the page. As Magpie outputs the RSS content without altering it, you would need to make any adjustments on the WP blog itself. Some solutions for this are to enable excerpts in the RSS feed not full posts or creating custom size descriptions using the WordPress Excerpt Editor plugin

If you want to bypass the problem altogether, simply remove the lines for the description and just show the blog post titles:


<?php
require_once($_SERVER['DOCUMENT_ROOT']."/path-to/magpie/rss_fetch.inc");
$num_items = 3;
$rss = fetch_rss('http://www.my-wordpress-feed-address');
$items = array_slice($rss->items, 0, $num_items);
foreach ( $items as $item ) {
$href = $item['link'];
$title = $item['title'];
$cat = $item['category'];
$date = date('M j\, Y', $item['date_timestamp']);
echo '<h4><a href="'.$href.'">'.$title.'</a></h4>';
}
?>

Anyway, sorry for the long and rather technical post but hopefully this will help with your Web 1.0. mashup creations. Good luck!

Nick Wilsdon is the Head of Content and Media at iProspect UK, part of the Densu Aegis Network. He manages online campaigns for the UK's leading telecom, finance and FMCG brands.

Comments

  1. Marty (aimClear) says

    This is a wonderful extrapolation of the basic concepts in the aimClearBlog post. Thank you for the information. I’ll Stumble it now!

    **NW** Thanks Marty for the posting idea, I hope people do find it useful. And much appreciated on the Stumbling ;)

  2. Michael Dorausch says

    Great tips and nice to see someone is building on Marty’s post. This method has to be the easiest way to add some life to a seemingly dead 1.0 legacy site.

    **NW** Thanks for dropping by Michael. Yes my appreciation of WP has grown steadily over the last few years. It’s perfect for a job like this. As Brian pointed out in the comments though, the difficulty is what to do next. Some clients run with it – others, well…

Trackbacks

Click on a tab to select how you'd like to leave your comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>