Displaying WordPress content within TerminalFour

Nick Mullen
Friday 1 June 2018

The following article is intended to provide a technical overview for an administrator of T4 with access to their community extranet site.

One of the current team objectives is to amalgamate a number of research related blogs into one centralised WordPress blog. The University’s research pages within the main website (published by T4) are to work in conjunction with the WordPress blog. The main website is to highlight significant blogposts, directing interested users to the blog in order to view the full article.

Some of our key considerations in resolving this problem are as follows:

  • The solution will need to provide WordPress users with a simple method for flagging blogposts to be displayed on T4.
  • The process will automatically update T4, avoiding the need to manually duplicate content.
  • The solution must not have a significantly negative impact on the time it takes to publish the main website.
  • Ideally, the approach will have some inbuilt redundancy, so that T4 pages can still be rendered even if the connection to WordPress should fail.
  • The solution should be generic so that it can be reused in other projects.

The solution that we came up with is comprised of three main elements: a WordPress plugin, a caching php script and a T4 data object. The overall process works like this:

  • T4 uses a data object to make a request for an RSS feed from the caching script.
  • In turn the caching script reads an RSS feed produced by the WordPress plugin, passing the resulting data back to T4.
  • T4 then renders the data onto the page.
WordPress to T4 data flow.

WordPress plugin

Whilst WordPress has inbuilt RSS functionality we needed more control over the output of the feed. So we opted to create a WordPress plugin.

The plugin’s main features are:

  • The ability to create a filtered RSS feed using tags or categories.
  • The ability to include a blogpost’s featured image within the feed.
  • The ability to insert a placeholder image into the feed if a post doesn’t have a featured image.
  • The ability to override the description text within the RSS feed.

The plugin can be found on GitHub.

RSS caching script

The RSS cache is a middle man in the process, sitting in-between T4 and WordPress. When T4 requests RSS from the cache, the cache script in turn requests RSS from WordPress and saves the resulting RSS and images locally on the server. If WordPress fails to respond to the request, the caching script returns the latest locally saved XML file.

T4 data object

The next part of the process is to enable T4 to read the RSS feed and render the results onto a page.

The following steps show how I rendered an RSS feed within T4:

1-Create a content type with an input field call URL.
2-Add the following tag into the default formatter of the content type.

<t4 type=”data-obj” method=”rss” rss-url=”$template.URL$” for-each=”item” formatter=”text/output” max-number=”5″ />

This code uses a data object type to read RSS from an entered URL and passes the results to the “text/output” formatter for rendering. More details on this tag can be found within the T4 documentation.

3-Create the text/output formatter.

The following formatter uses $ notation to refer to nodes within the RSS feed.

The above formatter is used to render a grid tile for each item in the RSS feed, applying our house style.

4-The final step it to add the content type to a page, entering in the URL of the RSS feed.

The plugin provides control over the RSS feed, whilst the caching script introduces redundancy into the process and the use of the T4 data object means we can display WordPress content on the main site without it being replicated within T4.

T4 bugs

During this development, I have discovered a few bugs within T4.

Enclosure tags

T4 cannot read the URL attribute from a standard RSS enclose tag such as this:

<enclosure url="http://example.com/file.mp3" length="123456789" type="audio/mpeg" />

Reformatting the tag to the following is an effective workaround. However, making this change will result in the feed will no longer being valid.

<enclosure url="http://example.com/file.mp3" length="123456789" type="audio/mpeg" > http://example.com/file.mp3</enclosure>

RSS data object URL

I have found that T4 cannot read an RSS feed where the URL dose not have any query parameters.

For example, I have found that T4 cannot read this feed:

The workaround is straightforward: just add a “?” to the end of the URL.

Hopefully these bugs will be fixed in future versions of T4.

See the forum pages and online documentation for more information on using RSS data feeds within TerminalFour.

Related topics