etc_url

9 April 2013, 11:02

Keywords: link, url, custom

This very simple plugin will take an url and modify its query string. The resulting url will preserve all unmodified parameters and respect the chosen permalink mode, so:

<txp:etc_url url="http://my.web.site/section/tag/?q=etc&pg=2" query="pg=3" />

will produce

http://my.web.site/tag/?q=etc&pg=3

in /section/title mode, and

http://my.web.site/index.php?s=tag&q=etc&pg=3

in messy mode.

The special txp parameters (id, s, etc) will receive a special treatment.

Attributes

  • url: url to rewrite, default is the page url.
  • context: article, file, image, link or empty. Use context="article" rather than url='<txp:permlink />' inside article lists.
  • query: &-separated list of tokens key or key=value, like this: key1=val1&key2&key3=val3. If val is not set, key will be removed from url.
  • sanitize: comma-separated URL parameters that should be transformed following the same rules as for article titles.
  • mode: permlink mode.
  • type: URL parameter to extract, default none (the whole URL). If type starts with &, it’s value will be URL-encoded.

Why would you need it?

To link to all articles posted by the current author within the same year and category, you could use

<txp:etc_url url='' query='c=<txp:category1 />&author=<txp:author />&month=<txp:posted format="%Y" />' />link</txp:etc_url>

For more advanced example, see here.

Some Textpattern-specific url variables:

  • id: article id
  • s: section
  • c: category
  • author: authors real name
  • month: publication date
  • pg: current page
  • q: search query string

History

Version 0.1: initial release.
Version 0.2: works in all url modes now. Added custom attribute.
Version 0.3: dropped custom, added sanitize and type attributes.
Version 0.4: added mode and context attributes.

File(s)