Using WordPress as news column

When building my latest web site (Slipstream Longboards) I figured that I should use some existing tools for the news column. Since I had some knowledge about WordPress I decided to go with that. What I wanted was to use the nice WYSIWG editor WordPress and also to have a nice way to generate the RSS Feeds.

I started reading on the WordPress web site and found that there is a nice API for this type of sites (See the Codex pages).

Basically, this is what I did:

  1. Installed WordPress
  2. Moved and transformed the old data
  3. Outputed the data from WordPress to a non WordPress page
  4. Outputed the data from WordPress to a RSS Feed

I will describe how I did step two, tree and four below. For more information about installing WordPress see the WordPress web site.

Move and transform the old data

Since the old data was a limited amount of data (about 10 news posts) I figured that I should just output the data and then do some text manipulation which made it compliant to the MovableType format and then import it into WordPress. This turned out to work well and I had the data inserted into WordPress in less than an hour.

Output the data to a page outside of WordPress

To get the data from WordPress I used the WordPress loop which is a way to query the database and output the data. It is realy easy to use.

First you include a file from WordPress using:

define('WP_USE_THEMES', false);
require('./news/wp-blog-header.php');

Then you can use the WordPress Loop.

if ( have_posts() ) : while ( have_posts() ) : the_post();
// Output your data here
endwhile;

To output for example the title and the body for your posts you use:

if ( have_posts() ) : while ( have_posts() ) : the_post();
the_title();
the_content();
endwhile;

It is possible to restrict the data to only output for example posts with a different author or to only output posts in a specific category. See the Codex page for more information about this.

Output the data from WordPress to a RSS Feed

To customize the RSS Feed for this web site I simply copied the wp-rss2.php from WordPress and changed;

  1. the URL to the web site to point to the first page for the web site instead of the first page for the blog
  2. the URLs to each item to be displayed on the web site instead of the blog
  3. I also had to include the wp-blog-header.php file (all as done above) and remove the include for the wp-config.php and delete the the call to the wp(feed=rss2)

And that produced a nice feed.

Publicerat av

Ola

Mångsysslande doer & klätterentusiast. Jag driver varumärket Sten & bloggen Klätterbilder. Jag konsultar inom IT & Marknadsföring samt undervisar inom webb på Folkuniversitetet. Jag älskar att fota. /// Doer & climbing enthusiast. I run the climbing brand Sten & the blog Klätterbilder. Consulting with IT & marketing & teaching at Folkuniversitetet. I love to take pictures.