Skip to the content of the web site.

All the News:

or Just the Headlines:

More Engineering News...

WordPress News Feed

We've installed a WordPress News Feed at http://www.eng.uwaterloo.ca/wordpress, where articles will be entered by the Dean's Office.

We've also created a script http://www.eng.uwaterloo.ca/rss2html.php that will extract articles from it for display within a webpage.

Selecting and Restricting Articles

Called without arguments, the script will return as many articles as WordPress is willing to give out at a time. The script can take a couple of arguments in its URL, to allow the user to select articles by category, and to limit the total number shown.

As an example, http://www.eng.uwaterloo.ca/rss2html.php?category=General will return any article with the word "General" in its category list. Articles, of course, may be classed in more than one category.

The categories of the most recent articles are:


To select articles from more than one category, use the format category=(one|another), a regular expression that will succeed if the category list contains the word "one", or "another". E.g. http://www.eng.uwaterloo.ca/rss2html.php?category=(Civil|Undergraduate) will select articles that have been classified as either "Civil" or "Undergraduate".

Three categories? category=(Research|General|Graduate)

To restrict the number of articles returned, add a "limit" variable to your URL; for example http://www.eng.uwaterloo.ca/rss2html.php?category=Architecture&limit=1 will return just the most recent article that was categorized under "Architecture".

Injecting Selected Articles into your Webpages

There are many ways to pull the articles into your existing webpages; the method you choose may depend on how your pages are created and maintained, and from what sort of server they are distributed, and on what sort of browser you expect they will be viewed.

Using JavaScript to select articles

Where you want news to appear, it's simplest to insert the line:

<script language="javascript" src="http://www.eng.uwaterloo.ca/rss2html.php?type=js&category=General&limit=2> </script>

into your page, which will return the articles which appear in the right-hand column of this page. ==Note that you need to include the "type=js" variable, so that the output in sent in the form of JavaScript commands, rather than html.

To deal with browsers without JavaScript (it's absent or disabled), you may want to include a line like:

<noscript>JavaScript is needed to display news articles.</noscript>

Using PHP to select articles

Similarly,

<?php readfile("http://www.eng.uwaterloo.ca/rss2html.php?category=General&limit=2"); ?>

will produce the same output in a PHP script.

Select articles with an SHTML File, on the same server as rss2html.php

<!--#include virtual="/rss2html.php?category=General&limit=2" -->

Select articles with an <IFRAME> tag

<iframe src="http://www.eng.uwaterloo.ca/rss2html.php?category=General&limit=2"> It's a good idea to include a URL inside the <iframe> tags. If the browser doesn't handle the tag, the viewer can still get to the news. </iframe>

HTML Format of the Articles

The output of the script is a set of nested <div> tags, with each part of the article as a different class. The classes associated with each <div> tag are:

To enclose the entire article with something other than <div>, add the parameter &tag=li or &tag=p or &tag=span to the URL. An example for formatting just the headlines as an unordered list appears below.

Hide and Seek with Stylesheets

Using a stylesheet, it's possible to manipulate the appearance of each article's components, to hide, highlight or position them. For the articles appearing in the right-hand column, the size of the rss_content, rss_pubdate, rss_category and rss_link classes were set to "0pt", and their visibility to "hidden":

<style>
.rss_content, .rss_pubdate, .rss_category, .rss_link {
    display: none;
    visibility: hidden;
    font-size: 0pt;
}
</style>

Show and Tell without Stylesheets

If you only want to show a couple of the components of the article, rather than hiding everything, you can add the parameter "show=" to the URL, to select just what you want: "show=link" will return just the link to the original article, "show=title,content" will return the title and content, and nothing else.

You can show a subset of link, title, category, pubdate, decription and content.

Hide and Seek or Show and Tell: Just the Headlines

So, if all you want is the headlines, you could hide everything else:

<style>
.rss_title, .rss_content, .rss_description, .rss_category, .rss_pubdate {
  display: none;
  visibility: hidden;
  font-size: 0pt;
}
</style>
<ul>
<script language="javascript" src="http://www.eng.uwaterloo.ca/rss2html.php?type=js&tag=li&limit=10"></script>
</ul>

or just request the links and nothing else:

<ul>
<script language="javascript" src="http://www.eng.uwaterloo.ca/rss2html.php?type=js&show=link&tag=li&limit=10"></script>
</ul>

All the News that's Fit to Print

In order to give users easy access to all the articles offered by the newsfeed, include a link like UW Engineering News as well.
<a href="http://www.eng.uwaterloo.ca/wordpress" 
title="News from UW Engineering">
UW Engineering News
</a>
-- PaulMcKone - 17 Aug 2006