Using WordPress for the Message Board

From PikaDocs

By Brian Lawlor & Mark Sawyer
Legal Services of Northern California (http://www.lsnc.net/)


Table of contents

Pika + WordPress = PikaPress?

Since late 2003, LSNC has been experimenting with blog publishing technologies, to explore different uses for them and evaluate the advantages and disadvantages of different blogging platforms. For example, LSNC currently uses Blogger (http://www.blogger.com/) to publish its Advocate Feed (http://www.lsnc.net/) at our main website; WordPress (http://wordpress.org/) to publish its Cases Feed (http://www.lsncweb.net/cases/) and Regs Feed (http://www.lsncweb.net/regs/); and, of course, the venerable Movable Type (http://www.movabletype.org/) to publish the OpenPika site.

It is the Pika CMS itself that gave us our latest idea about using blog publishing technology. Here's what happened: We're slogging our way through the alpha version (http://www.openpika.org/archives/2005/03/whats_it_all_ab.html) of the Pika redesign and working on the Pika CMS Home Page. Of course, one of the built-in features of Pika is the Message Board on the Pika home page:


Pika Message Board


And a very nice feature it is. From the Message Board screen one can enter a "message of the day" that automatically gets published to all end users:


Message Board entry screen


Good stuff. And we liked what we came up with (http://www.openpika.org/images_pika/alpha_home_test.html) for restyling this default feature in the alpha version. But then we started looking to do more with the Message Board. What about ... embedded links within the message ... date stamps ... archives by date and by category ... message-board only searches, etc. As we talked out loud about it, we realized we were missing the forest for the trees. We were talking about something we were already familiar with and using: a blog. So, we asked ourselves, how do we integrate a blog into Pika? Pika is PHP, right? Which of our current blog favorites is also PHP? WordPress (http://wordpress.org/). That's the ticket: Pika + WordPress = PikaPress. We had our new alternate for the Message Board.

Our initial take on how to do this is a bit down and dirty, but what follows explains how we did the initial construction of the new Message Board. No doubt we will make further technical changes down the road, but we did what we're doing for the early Claire beta redesign (http://www.openpika.org/archives/2005/04/codename_claire.html) in five easy steps:

Step 01: Install WordPress on your Pika server

You're already running Pika, right? Just download (http://wordpress.org/download/) WordPress 1.5 and install it on the same server. (And, yes, it is true as advertised: You're looking at a five- minute install (http://wordpress.org/docs/installation/5-minute/), tops.) Make sure you install the latest version (http://wordpress.org/download/) of WordPress because it includes the plugin you'll need for the next step. Also, be sure to configure the name of your WordPress blog so it is "Message Board," "Program News and Alerts," whatever it is you want to appear on the Pika Home Page. As explained below, what you choose here for the blog name will replace the Pika default "Message Board" title, so think about it some. (Although, not to worry. You will always be able to later change the blog name from within WordPress.)

Step 02: Activate the CG-Feedread plugin

From the WordPress start page select select Site Admin; then from the Dashboard screen select Plugins; from the Plugin Management screen you can see a list of about a dozen plugins that come with WordPress. Locate the CG-Feedread plugin. In the right Action column, click "Activate" to make the plugin active and operational. As highlighted in this screenshot in yellow, once you've done it, the link should change to read "Deactivate" ...


WordPress Plugin screen

Step 03: Validate your WordPress feed

At this point you should have an active RSS feed (http://en.wikipedia.org/wiki/Rss_feed) working at your freshly installed WordPress site. But you want to make sure before you move on. Easy enough. First, post some blog entries so there is actually some content in the "feed," and then target your favorite feed reader at your WordPress site. While you're at it, validate your feed (http://feedvalidator.org/) to make sure there aren't other latent problems with the feed. Good to go? Onward to Pika to do the feed integration.

Step 04: Modify the index.php file

You'll need to change some code in two files: index.php, which provides the PHP code instructions for generating the content in the [motd] field, which in turn is displayed in the browser within the home.html template.

First, let's modify the index.php file, located in the Pika root directory. You need to neutralize the existing Pika code instructions that create its default [motd] ("message of the day") behavior. To do this, you can either delete the code; or you can "comment out" the code by placing double forward slashes at the beginning of lines 17 through 31. Assuming you want to keep the old code in place and just comment it out, once done it should look like this:


index.php file at lines 17-31


To make this all work, you need to substitute a new $messages_text variable for the one you commented out in line 20. The new variable declaration ($messages_text .= $feedOut;) tells Pika that the source of the message board text is now coming from the new WordPress feed output. To accomplish this, add the new code code (without any forward slashes, of course) below the original $messages_text declaration in line 20. Those two lines should now look like this:

// $messages_text .= "<blockquote><tt>Welcome to the Pika Case Management System!</tt></blockquote>\n";

$messages_text .= $feedOut;

Next, at the top of the index.php code, in between the two existing require_once (http://www.php.net/manual/en/function.require-once.php) functions beginning at line 8, you need to add a third require_once function ...

require_once('/var/www/html/wordpress/wp-blog-header.php');

... that tells Pika where to locate the WordPress blog you installed earlier; and two additional lines of code ...

$feedUrl = "http://webdogs.org/wordpress/wp-rss2.php";
$feedOut = getSomeFeed($feedUrl, 5, true, "feed-cache_pika", '', -1, -1, false);

... so that Pika knows which feed URL to use (here, wp-rss2.php) and then knows it needs to pass the feed variables to the Feedreader plugin.

The eight getSomeFeed( ) variables used in the above example are not well documented, but here's what we learned from harvesting the WordPress forums:

Example:

getSomeFeed($feedUrl, 5, true, "feed-cache_pika", ' ', -1, -1, false);

In order, the variables are:

  1. The feed/RSS URL
  2. The total number of feed items to display
  3. Set to "true" to show feed item details; set to "false" to show only feed item titles
  4. Unique filename to cache the feed on disk for speed
  5. Optional (leave as ' ' ) filter on feed items for a category string
  6. Character limit for titles (-1 == none)
  7. Character limit for descriptions (-1 == none)
  8. Set to "false" to show embedded HTML (including links); set to "true" to NOT show embedded HTML

Putting all this together, here's the sample code below, with descriptive comments added and highlighted in yellow. In this example, we use the webdogs.org server and domain locations to state where Pika and WordPress are located:


index.php file at lines 8-18

Step 05: Modify the home.html template

You're almost done. All that's left is to make some minor edits to the home.html template at lines 63-71. At that location in the file, the code for displaying the Message Board is embedded within the second TD element (http://www.htmldog.com/reference/htmltags/td/) of the TABLE (http://www.htmldog.com/reference/htmltags/table/) used to position the middle "content" area of the home page:

<td>

<h2>Message Board</h2>
%%[begin:motd]%%
<p>
    <em>By %%[staff_name]%%</em><br />
    <blockquote>
	%%[content]%%
    </blockquote>
</p>
%%[end:motd]%%

</td>

Leave the TD tags untouched, but delete or comment out everything between lines 63 and 71 EXCEPT the  %%[begin:motd]%%  and the  %%[end:motd]%%  field declarations. Those two lines of code are still needed to instruct Pika where to place the new feed output. The code, with the parts that are commented-out highlighted in yellow, should now look like this:


home.html file at lines 63-71


Upload your changes to the index.php and home.html files and you are good to go, my friend. Now whenever you add an item to the WordPress blog you intalled earlier, it will automatically appear as a feed item on the Pika Home Page. Remember, as mentioned above, the WordPress blog is now the new source of the H2 heading (http://www.htmldog.com/reference/htmltags/h1h2h3h4h5h6/) element that you commented out, above.

Also, in this new configuration, if you click on the new Message Board heading on the Pika Home Page, the embedded link will jump you to the blog home page, where you can access everything at the blog, i.e., change the blog name, add or edit postings, search for prior postings, etc.

In a related article as part of the Claire redesign, we'll explain how you can apply CSS code to change the style of this new Message Board configuration using WordPress. Stay tuned.


Related articles: