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.
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.
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:
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.
To install RelatedContent you need:
Install RelatedContent as follows:
Download, install and configure the Views module, following the instructions for that module.
Download the latest stable version of RelatedContent from its project page.
Unpack the downloaded file into sites/all/modules
or the modules directory of your site.
Go to admin/build/modules
and enable the module.
RelatedContent is enabled and configured for each content type individually as described below:
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.
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.
Check the checkbox named Enable to allow related content of nodes for this particular content type.
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.
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.
Choose among the radio buttons named Teasers, whether related content should be shown in teasers.
Choose among the radio buttons named Output format, whether the related content should be viewed as teasers or bodies of the selected nodes.
Choose among the radio buttons named Grouping, whether the related content should be grouped by content type, author or not at all.
Choose among the radio buttons named Placing, whether the related content should placed at the beginning or at the end of the body.
When viewing a node of a content type with RelatedContent enabled, select nodes to be shown as follows:
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.
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.
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.
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.
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.
The RelatedContent module provides following themable functions:
theme_relatedcontent($output, $grouped, $teaser, $page)
, where
$output
is an associative array, whose keys are the names by which the output should be grouped, i.e. the name of content types or authors, depending on the settings, or 'all'
if grouping is disabled. Each output buffer is an ordinary array with already themed nodes which should be outputted in index order as they are.
$grouped
is the string 'type'
if the related content should be grouped by their content types, the string 'name'
if it should be grouped by their authors, and false
if it should not be grouped at all.
$teaser
is true
or false
depending on whether the node, whose related content is themed, will be displayed as a teaser or in full, respectively.
$page
is true
or false
depending on whether the node, whose related content is themed, will be displayed as a page itself or embedded into another page, respectively.
The default implementation returns the default theming described in the previous subsection.
theme_relatedcontent_form($form)
, where
$form['intro']
is a introductory text,
$form['nodes'][$n]
is the form element for a checkbox,
$form['title'][$n]
is the form element for a title,
$form['name'][$n]
is the form element for a content type,
$form['created'][$n]
is the form element for a create time,
$form['username'][$n]
is the form element for an author, and
$n
is the nid of the node in question.
The default implementation returns the themed table used to select nodes whose teasers are going to be shown.
The RelatedContent module will be further developed. Following issues are known and will be dealt with in future versions of the module:
The order of the teasers shown is not subject to the sort order setup in the view that filter nodes to be used by the RelatedContent. This will change in a near future.
Only one view of the Views module can be used to select nodes from. This will change in a near future.
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.
The development of this module has been sponsored by
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.