Help?

related articles

From Textpattern CMS User Documentation

<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.

When used as a container tag, 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.

Contents

Attributes

Tag will accept the following attributes (case-sensitive):

form="form name"
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="category number(s)"
Restrict to articles related by specified category.
Values: "Category1", "Category2", "Category1,Category2".
Default: "Category1,Category2".
no_widow="boolean"
Whether to inhibit line breaks in titles which would leave just a single word on the last line (widows).
Values: 0 single words allowed; 1 single words not allowed on their own line
Default: Whatever is set in Advanced Preferences
section="section name(s)"
Restrict to articles from specified section(s).
Values: (comma separated list of) section name(s).
Default: unset.
sort="sort value(s)"
How to sort resulting list.
Values:
ID (article id#)
AuthorID (author)
LastMod (date last modified)
LastModID (author of last modification)
Posted (date posted)
Title
Category1
Category2
comments_count
Status
Section
Keywords
Image (article image id#)
url_title
custom_1 through custom_10
(From 4.2.0 on: custom_n)
rand() (random).
Default: Posted desc.

Common Presentational Attributes

These attributes, which affect presentation, are shared by many tags. Note that default values can vary among tags.

label="text"
Label prepended to item.
Default: unset (but see label cross-reference for exceptions).
labeltag="element"
HTML element to wrap (markup) label (e.g., labeltag="h3")
Default: unset.
wraptag="element"
HTML element to wrap (markup) list block (e.g., wraptag="ul")
Default: unset (but see wraptag cross-reference for exceptions).
class="name"
HTML class to apply to the wraptag attribute value.
Default: tag name or unset (see class cross-reference)
break="value"
Where value is an HTML element (e.g., break="li") or some string to separate list items.
Default: br (but see break cross-reference for exceptions).

Examples

Example 1: Labelled list of related articles

<txp:related_articles label="Related" limit="5" />

Example 2: Related articles as an unordered list

<txp:related_articles label="Related" limit="10" break="li" wraptag="ul" />

Styles could go this way

.related_articles {
     list-style-type:none;
}

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.0.6

  • support added for comma separated list for section attribute

Version 4.0.7

  • Can be used as a container tag.
  • form and no-widow attributes added.
Translations [?]