Skip to content
Everett Griffiths edited this page Feb 14, 2015 · 8 revisions

getPagesByTerm

Returns a list of pages associated with the given term or its children.

Parameters

  • &outerTpl (string) Format the Outer Wrapper of List using a Chunk or a formatting string. (Optional). Default: <ul>[[+content]]</ul>
  • &innerTpl (string) Format the Inner Item of List using a Chunk or a formatting string. Default: <li><a href="[[~[[+Page.id]]]]">[[+Page.pagetitle]]</a></li></li>
  • &term_id (integer) Page id of the term (optional: defaults to the current page id)
  • &exact_matches (boolean) if true, implied hierarchies are ignored and only pages assigned specifically to term_id will be returned. The default behavior is to return implied matches, which include pages associated with the Term's children. Default: false.
  • &classname (string) Set this if you have created a custom join table used to associate taxonomy terms with something other than pages. (optional: default PageTerm)
  • &debug (boolean) if set, will output debugging info including raw SQL query and parameter list.
  • &limit (integer) Limit the result
  • &sort (string) Sample Value, Page.id, Page.pagetitle. Just Add Page before the actual field name.
  • &dir (string) ASC or DESC, default to ASC.

Note that the placeholders in the innerTpl Chunk use a prefix of Page. -- this is a by-product of the underlying SQL join that joins from the PageTerms to the Page. See usage examples below.

Usage

This Snippet is used to show all pages that have been associated with the given term_id or its children.
Commonly this Snippet would be placed on the Term pages themselves (or in the template used by the term pages).

Used on a Term page:

[[getPagesByTerm]]

Specify a summary of a specific term:

[[getPagesByTerm? &term_id=`123`]]

Specify a custom format:

[[getPagesByTerm? 
    &innerTpl=`<li><a href="[[~[[+Page.id]]]]">[[+Page.pagetitle]]</a></li>`
]]

Return only exact matches:

[[getPagesByTerm? &exact_matches=`1`]]

This alters the behavior of the matching. Normally, if you request pages matching the given term, the Snippet returns pages that match the term or the term's children. For example, searching for pages matching the "Mammals" term would by default also return "Dogs" (given that "Dogs" is a sub-term of "Mammals"). To bypass this hierarchical querying, set &exact_matches to 1, and a page will be included in results only if it had been explicitly checked with the given term.

Show a message if no matches:

[[getPagesByTerm:empty=`Sorry, no matches`? &term_id=`123`]]