Related articles
Contents
Syntax
<txp:related_articles>
The related_articles tag can be used as either a single tag or a container tag, and is used to produce a list of related (by category) articles.
If used as a container, it must be specified as an opening and closing pair of tags, like this:
<txp:related_articles>
…contained statements…
</txp:related_articles>
This is equivalent to putting the contained statements into a form named ‘my_form’ and using <txp:related_articles form="my_form" />.
Related matches are selected as follows:
If a match to category 1 (category1) or category 2 (category2) of the individual article being displayed is found in either category 1 or category 2 of any other article in the database, it will cause that article to be listed as related.
If category 1 of the individual article being displayed is left blank and category 2 is not blank, then all other articles are selected as being related. If both categories are left blank, then no articles are selected.
Attributes
Tag will accept the following attributes (case-sensitive) as well as the global attributes :
form="form name"v4.0.7+- Use specified form.
- Default: unset. If left empty, the permlinked article title(s) will be displayed.
limit="integer"- Number of articles to display.
- Default:
10. match="match type"- Restrict to articles related by specified category, author, keywords and/or custom field (when matching by custom fields, match type is
exact). - Values (comma separated):
author.
category1.
category2.
customfieldnamewherecustomfieldnameis the name of your custom field.
keywords. - Default:
category1,category2. no_widow="boolean"v4.0.7+- Control widows](https://en.wikipedia.org/wiki/Widows_and_orphans) and overrule ‘widows’ setting in the [Preferences panel.
- Values:
0allow the last word in the title to appear on its own line, i.e. the title content is rendered unchanged,1ensure the last word is not left on its own line - Textpattern inserts an invisible code (a non-breaking space) between the last two words. - Default: as set in the Preferences panel.
offset="integer"v4.6.0+- The number of articles to skip.
- Default:
0. section="section name(s)"- Restrict to articles from specified section(s).
- Values: (comma separated list of) section name(s).
- Default: unset, retrieves from all sections.
sort="sort value(s)"- How to sort the resulting article list. Specify a value from the ones below, followed by a space and then add either
ascordescto sort in ascending or descending order, respectively. Note: values are case sensitive on some servers. - Values:
AuthorID(author name).
Category1.
Category2.
comments_count.
custom_nwherenis the number of your custom field - for numeric values use(custom_n+0).
ID(article id#).
Image(article image id#).
Keywords.
LastMod(date last modified).
LastModID(author name of last modification).
Posted(date posted).
rand()(random).
Section.
Status.
Title.
url_title. - Default:
Posted desc.
Common presentational attributes
These attributes, which affect presentation, are shared by many tags. Note that default values can vary among tags.
break="value"- Where value is an HTML element, specified without brackets (e.g.
break="li") or some string to separate list items. - Default:
br(but see break cross-reference for exceptions). breakby="integer"v4.7.0+- Used to group list items when separating by
break. Possible values are lists of integers, like2(groups of 2 items) or1,2(alternate groups of 1 and 2 items). - Default:
1(actually unset). class="class name"- HTML
classto apply to thewraptagattribute value. - Default: tag name or unset (see class cross-reference).
label="text"- Label prepended to item.
- Default: unset (but see label cross-reference for exceptions).
labeltag="element"- HTML element to wrap (markup) label, specified without brackets (e.g.
labeltag="h3"). - Default: unset.
wraptag="element"- HTML element to wrap (markup) list block, specified without brackets (e.g.
wraptag="ul"). - Default: unset (but see wraptag cross-reference for exceptions).
Examples
Example 1: Labelled list of related articles
<txp:related_articles label="Related to this:" limit="5" />
Example 2: Related articles as an unordered list
<txp:related_articles label="Related" limit="10" break="li" wraptag="ul" />
Example 3: Used as a container tag
<txp:related_articles label="Related" labeltag="h3" limit="10" break="li" wraptag="ul">
<txp:permlink>
<txp:title />
</txp:permlink>
by
<txp:author />
</txp:related_articles>
Other tags used: permlink, title, author.
Genealogy
Version 4.7.0
breakby attribute added.
Version 4.6.0
offset attribute added.
match attribute allows author, keywords and custom field values.
Version 4.0.7
Can be used as a container tag.
form and no-widow attributes added.
Version 4.0.6
Support added for comma separated list for section attribute.