Bloge-Tags

Summary: Use page keywords and categories as tags
Version: 2009-10-13
Prerequisites: PmWiki 2.2.x
Status: beta
Maintainer: Eemeli Aro
Categories: Blog, Links, Categories, PHP72
Discussion: Bloge-Tags-Talk

Description

Bloge-Tags adds easy tagging to PmWiki by letting the built-in (:keywords:) directive and [[!Category links]] also define page tags, which may be listed with a page variable {$TagList} or with a pagelist for a tag cloud.

Bloge-Tags is a part of Cookbook.Bloge, but may also be used as a standalone recipe.

To install this recipe:

  • download bloge-tags.phpΔ to your cookbook directory
  • add the following line to your configuration file:
    include_once("$FarmD/cookbook/bloge-tags.php");

Usage

By default Bloge-Tags assumes that page keywords, categories and tags all mean the same thing, but is configurable to believe otherwise. Hence you may use (:keywords word1, word2, ...:) and [[!Category links]] as usual to also define page tags, which may be then listed using a new page variable {$TagList}.

{$TagList}
A comma-separated list of all tags for this page, as category links.
{$TagCount}
The number of tags for this page; returns '' for none.
(:pagelist fmt=tags:)
A tag cloud of all the tags from pages matching the pagelist parameters.

A few of the parameters are handled separately, as count and order (valid values are name, -name, freq, -freq) control how the tags, not pages, are listed.

An additional option tagfilter accepts a comma-separated list of filter rules for including or excluding tags (prefix with - to exclude, wildcards ?* are ok).

Configuration

The following variables may be set in your config file to control the way Bloge-Tags works.

$BlogeTag['group']
default: $CategoryGroup
The group to use for tags. If set to something other than $CategoryGroup (which in turn by default is 'Category') category links won't get listed as tags.
$BlogeTag['linkfmt']
default: '[[!$TagName]]'
How to make a link from a tag name. In order to get your tag list without links, use $BlogeTag['linkfmt'] = '$LinkText';. Markup and HTML are both supported.
$BlogeTag['listfmt']
default: '%font-size=$sizepct%[[!$tag]]%% '
How to make a tag cloud link from a tag name. The following strings will be replaced by corresponding values: '$tag', '$count', '$group', '$size'. For an alternative unordered list, you could use $BlogeTag['listfmt'] = '* %item font-size=$sizepct% [[!$tag]]'."\n";.
$BlogeTag['min-size']
default: 80
$BlogeTag['max-size']
default: 160
The minimum and maximum values of $size in $BlogeTag['listfmt'], corresponding to $count values of 1 and the maximum for the current list.
$BlogeTag['prefix']
default: '$[Tags]: '
The string to add at the beginning of the tag list when at least one tag is present, in markup.
$BlogeTag['separator']
default: ', '
The string separating tags from each other, in HTML.
$BlogeTag['tagfilter']
default: ''
An array in the style of MatchPageNames $patterns for including or excluding tags in the tag cloud, appended to by the tagfilter= option.

Notes

For speed, the list of tags is generated from the page targets array, which is set when the page is edited. Hence if you've defined keywords for your pages before including the recipe, those keywords won't get listed as tags until you've at least once saved the page (no need to make any changes, just save the page).

The templating/formatting of tag lists for single pages and for pagelists is a mess at the moment. Fixing this will probably happen once PITS.01102 gets resolved.

The recipe may be included in a per-group or per-page customization file to limit its functionality to that group or page.

It might be a good idea to use EditAttributes to add a separate edit field for the page keywords to your editing form.

The easiest way to get category links to not show on the page is to use %comment%[[!Category]]%%. For a more thorough solution try adding $LinkCategoryFmt = ' '; to a config file. That'll hide all your category links but still let them get listed using {$TagList}. Note that the format string can't be empty or it'll get ignored.

Release notes

See also

Contributors

Comments

See discussion at Bloge-Tags-Talk

User notes +2: If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.