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 archive file with the latest stable version from RelatedContent project page.
Unpack the downloaded archive into sites/all/modules
or the modules directory of your site.
Go to admin/build/modules
and enable the module.
RelatedContent is configured for each content type individually. By default, it is turned off. To enable RelatedContent for a particular content type, do as follows:
If not already existing, go to admin/build/views
and add at least one view that filter nodes to be used by the RelatedContent.
Go to admin/content/types/<type>
, where <type>
is the name of the content type, e.g. page
or simplenews
, and locate the RelatedContent settings.
In the pull-down menu named RelatedContent view, select the view that that filter nodes to be used by the RelatedContent. Leave empty to disable RelatedContent.
In the pull-down menu named Max number of nodes, select the maximum number of nodes to be available for the RelatedContent.
When creating or editing a node of a content type with RelatedContent enabled, select nodes to be shown as follows:
Locate and open the collapsible section called Related content.
Check the checkboxes to the left of the nodes whose teasers are going to be shown.
The default theming of nodes with related content is the body followed by a sequence of
<div class="relatedcontent-nodes $nodetype"> <h3>$nodetype</h3> $nodeteasers </div>
where $nodetype
is the name of a content type, and $nodeteasers
is teasers of all nodes of the named content type. The teaser of a node $nodenode is styled by node_view($nodenode, true).
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 theamable function theme_relatedcontent()
discussed below.
The RelatedContent module provides following themable functions:
theme_relatedcontent($nodebody, $nodenodes)
, where
$nodebody
is a string with the already themed body of the node itself, and
$nodenodes
is an array with nodes whose teasers are to be themed and appended to the body.
The default implementation returns the default theming described in the previous subsection.
theme_relatedcontent_form_alter_node($nodeform)
, where
$nodeform['nodes'][$noden]
is the form element for the checkbox,
$nodeform['title'][$noden]
is the form element for the title,
$nodeform['name'][$noden]
is the form element for the type,
$nodeform['created'][$noden]
is the form element for the create time,
$nodeform['username'][$noden]
is the form element for the author, and
$noden
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 future version of the module.
The view that filter nodes to be used by the RelatedContent is configurable on content type basis. A future version of the module might provide means for privileged users to override this configuration on node basis.
The themable function can only append the teasers to the body. A future version of the module might provide an input filter that allows the teasers to be embed into the body of the node itself.
The RelatedContent section shows a configurable number of nodes. If there is more nodes than can be shown, they are left out. A future version of the module might instead provide a pager.
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.