Textpattern CMS Template Tags

<txp:related_articles /> sing/cont tag, 6 attributes

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 Cat1 or Cat2 of the individual article being displayed is found in either Cat1 or Cat2 of any other article in the database, it will cause that article to be listed as related.

If Cat1 of the individual article being displayed is left blank and Cat2 is not blank, then all other articles are selected as being related. If both Categories are left blank, then no articles are selected.

attributes

section="unset" 
  • Restrict to articles from specified section(s).
  • Values: (comma separated list of) section name(s).
match="Category1,Category2" 
  • Restrict to articles related by specified category.
  • Values: “Category1”, “Category2”, “Category1,Category2”.
sort="Posted desc" 
  • Values
    • ID (article id#)
    • Posted (date posted)
    • Expires (expiry date)
    • AuthorID (author name)
    • LastMod (date last modified)
    • LastModID (author name of last modification)
    • Title
    • Image (article image id#)
    • Category1
    • Category2
    • comments_count
    • Status
    • Section
    • Keywords
    • url_title
    • custom_1 through custom_10
      • Note: Each field in the “textpattern” table can be used as a sort key.
    • rand() (random)
  • Direction
    • asc (ascending)
    • desc (descending)
limit="10" (integer) 
  • Number of articles to display.
form="unset" 
  • Use specified form.
  • If left empty, the permlinked article title(s) will be displayed.
no_widow="Whatever is set in Advanced Preferences" (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

presentation

label="unset" 
  • Label prepended to item (or as first list item, where appropriate).
  • if wraptag is available and is set to ol or ul, the label will be the first list item.
labeltag="unset" 
  • (X)HTML tag (without brackets) to wrap around label.
break="br" 
  • (X)HTML tag (without brackets) or string to separate list items.
wraptag="unset" 
  • (X)HTML tag (without brackets) to wrap around the list.
class="related_articles" 
  • (X)HTML class attribute to apply to the wraptag.

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.
<txp:related_articles /> 3 examples

Labeled list of related articles

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

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;
}

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.