RelatedContent

RelatedContent is a Drupal module that allows privileged users to assemble teasers at the end of a node. The teasers are selected from a list of nodes. The list is provided by a view from the Views module. The number of nodes and the view to get them from are configurable for each node type.

Background

It is very common for websites to plug for material on the site by presenting abstracts, which in Drupal idiom is called "teasers". There are many great solutions for doing this in Drupal: taxonomy, views and queues, to mention a few. In spite of these possibilities, there is still need for an alternative way of compiling teasers to be shown. In this section, a quick review of some possibilities are given, and the need for an alternative is explained in the context of an actual use case.

Alternatives

Special pages with teasers are provided out of the box for nodes that are categorized by the core Taxonomy module. If your needs are more elaborative, you can compile a such page (or block) yourself with the wonderful Views module. In both cases, you cannot directly select which teasers to show. Instead you are reduced to setup conditions for the viewed teasers to meet.

To directly select teasers to show, you can resort to the Node Queue module. With the Node Queue module, you can create a "queue", which is a named set of references to nodes. You add references by visiting the nodes one by one or en masse by using the Node Queue Builder module. Once created, you can embed a PHP snippet into a node or a block to view teasers of the nodes referenced by a particular queue.

Although powerful, the Node Queue approach is not always suitable. To understand why, consider the cause for writing the RelatedContent module in the first place:

Use case

The Simplenews module can be used to provide newsletters for visitors to subscribe to. The module provides a particular content type called "Newsletter issue". When editing a newsletter issue, the editor has a single text-area for the content. It is suitable for self-contained newsletters. However, it cannot easily be used to accomplish newsletters made up of an introductory text followed by teasers to articles already published on the website. RelatedContent was developed to extend Simplenews (and other content types) with this possibility.

So why is Node Queue less appropriate for this particular purpose? There are at least two reasons:

First, it would be necessary to write PHP code in order to pull out teasers from the nodes referenced by a queue. Probably the editor of a newsletter issue is not a programmer, and hence not comfortable with (or versed in) writing PHP code. It is also a security risk since the editor must have a role with the privilege to use the PHP code input format.

Second, and a little more subtle, but nevertheless a problem, is the fact that changes in a queue is propagated to wherever the queue is used. For a newsletter to not change on the web after it has been published, the queue must not be altered. The implication is that it is necessary to setup a unique queue for each issue, which is not feasible in the long run.

Both these problems are overcome by using the RelatedContent module.

Requirements

To install RelatedContent you need:

Installation

Install RelatedContent as follows:

  1. Download, install and configure the Views module, following the instructions for that module.

  2. Download the latest stable version of RelatedContent from its project page.

  3. Unpack the downloaded file into sites/all/modules or the modules directory of your site.

  4. Go to admin/build/modules and enable the module.

Configuration

RelatedContent is enabled and configured for each content type individually as described below:

  1. If not already existing, go to admin/build/views and add at least one view that can be used to provide RelatedContent with nodes to select from.

  2. Go to admin/content/types/type, where type is the name of a content type, e.g. page or simplenews, and locate the RelatedContent settings. Click on the name to expand the fieldset.

  3. Check the checkbox named Enable to allow related content of nodes for this particular content type.

  4. In the pull-down menu named RelatedContent view, select the view that will provide the nodes to select from. If no view is selected, the table with nodes to select from is disabled. Any previously selected nodes will remain selected.

  5. In the pull-down menu named Length of node table, select the number of nodes to shown on each page of the table with nodes to select from.

  6. Choose among the radio buttons named Teasers, whether related content should be shown in teasers.

  7. Choose among the radio buttons named Output format, whether the related content should be viewed as teasers or bodies of the selected nodes.

  8. Choose among the radio buttons named Grouping, whether the related content should be grouped by content type, author or not at all.

  9. Choose among the radio buttons named Placing, whether the related content should placed at the beginning or at the end of the body.

Usage

When viewing a node of a content type with RelatedContent enabled, select nodes to be shown as follows:

  1. Next to the usual View and Edit tabs, there is a RelatedContent tab. Click on it. You can also go directly to node/nid/relatedcontent where nid is the identity number of the node.

  2. Underneath the RelatedContent tab, there is two subtabs. The first subtab is called List nodes and is chosen by default. When the first subtab is chosen, a table of all selected nodes is presented. The other subtab has the same name as the view that provides nodes available to select from. When the other subtab is chosen, a paged table of all nodes provided by the named view is presented. If there are more nodes than the table is configured to view, there is a Next-button on all pages except that last, and a Previous-button on all pages except the first. Use these buttons to navigate through the table's pages.

  3. In the tables of nodes, each node is presented on a row with its title, type, creation time and author. Leftmost on the row, there is also a checkbox. The related content will be those nodes that are checked when the Update button is pressed.

Theming

The default theming of nodes with related content is appended at the beginning or end, depending on the settings, with a sequence of following HTML-blocks:

  <div class="relatedcontent-nodes $group">
  <h3>$group</h3>
    $contents
  </div>

where $group is, depending on the settings, the the name of the content type or the author or all; and $contents is, depending on the settings, the teasers or bodies of the related content after theming with node_view(). The <h3>-line is excluded if grouping is disabled.

Template file

The easiest way to change this theming, is to copy relatedcontent.tpl.php from the folder with the RelatedContent module, e.g. site/all/modules/relatedcontent, to the folder containing the theme's page.tpl.php and edit is as needed. This works for all themes based on the built-in PHPTemplate theme engine.

For advanced themers, and themes not based on the PHPTemplate theme engine, it is possible to override the themable function theme_relatedcontent() discussed below.

Themable functions

The RelatedContent module provides following themable functions:

Plans for the future

The RelatedContent module will be further developed. Following issues are known and will be dealt with in future versions of the module:

Author

RelatedContent module was developed by Thomas Barregren. The author can be contacted for paid customizations of this module as well as Drupal consulting, installation, development, and customizations.

Sponsors

The development of this module has been sponsored by

License

RelatedContent. Copyright © Thomas Barregren.

RelatedContent is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

RelatedContent is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.