Table of Contents

Tag Plugin

Compatible with DokuWiki

  • 2017-02-19 "Frusterick Manners" yes
  • 2016-06-26 "Elenor Of Tsort" yes
  • 2015-08-10 "Detritus" yes
  • 2014-09-29 "Hrun" yes

plugin Assign category tags to wiki pages

Last updated on
2017-08-24
Provides
Syntax, Helper, Action
Repository
Source
Requires
pagelist

Tagged with blog, listing, navigation, tags

:!: The 2013-02-15 release fixed a security issue (XSS vulnerability), if you are using an older version of the tag plugin you should upgrade ASAP! :!:

Description

The Tag Plugin lets you assign category tags to wiki pages.

Updating from before 2012-08-24: Please remove the tag plugin and re-install it as the plugin manager has a bug so the update won't remove no longer needed parts of the plugin. This is a large change to the way the tag plugin stores the tags. If you don't want to wait till the tag index is automatically rebuilt by visiting the pages with the tags, you can rebuild the tag index manually. You also need to update the cloud plugin or the tag cloud won't work anymore.

Components

Tag

{{tag>[list of tags]}}
[list of tags] a space separated list of tags that describe the content of the current page required

Allows you to categorize your wiki pages. The resulting links either point to the corresponding page in the specified tag namespace (only if it exists). If you want a link to point to a page in another namespace, you have to indicate the namespace before the tag name. If this page doesn't exist, just the list of pages with the same tag is shown when you follow one of those links.

Examples:

Topic

{{topic>[tag]&[flags]}}
[tag] the category tag for which you want a list of pages required
[flags] pagelist flags delimited by &, see flags optional

This displays a list of all pages that contain the given category tag. The list is sorted alphabetically by page ID. You can also prepend the modifiers + and -. + creates an intersection between the list of pages created by the already defined tags and the pages matching the tag following the + (AND), - removes all pages tagged with the given tag from the list of already found pages.

Example:

Searchtags

 {{searchtags&[flags]}}
[flags] pagelist flags delimited by &, see flags optional

This displays a search form with the possibility to select a namespace and to select tags from a table of all tags that should either be in- or excluded with the option to choose if the tags should be associated with AND or OR. The results are displayed as in the topic component.

This is a great feature which you should not miss. Please add a screenshot of this cool feature. FIXME

And you might check out TagFilter Plugin for similar purpose but in different scenarios.

Example:

Count

{{count>[tag]}}
[tag] the category tag for which you want to list the occurrence required

This part allows you to display an overview of your current used tags. It prints the tag and the related occurrence (how often is the tag used?) in your wiki. Either you can specify a + as tag-name, which results in a list of all used tags or just specify some tags separated by spaces.

Example:

Tagpage

 {{tagpage>[tag][&dynamic][|title]}}

This displays a link to the listing of all tags as it is done by the Tag syntax but without tagging the page with that tag. With the optional dynamic flag the link becomes red when the listing of all pages with that tag is empty for the current user. The dynamic flag automatically disables the cache of the current page in order to ensure that the link color is always correct. Optionally a title can be specified that will be used as link name.

Example:

Configuration

The plugin can be configured with the DokuWiki configuration manager available in the admin menu.

namespace Namespace where the tag plugin looks for existing tag pages and links to them instead of the default tag overview. You could use the topic component to display the list of tags on such a page for example. (default tag)
sortkey Order in which tagged pages are sorted in the topic overview; available options are cdate as creation date, mdate as modification date, pagename, id as page ID, ns as namespace and title
sortorder Sort order of the topic overview.
pagelist_flags Comma separated Flags of the pagelist plugin which is used to display the topic overview
toolbar_icon Show icon in page editor toolbar to add tags.
list_tags_of_subns When counting tags in specified namespaces include also tags in subnamespaces.
tags_list_css Choose tags list style between standard or optimised for top of page position.

Tagindex Rebuild

If the tag index becomes corrupted somehow (such as by using page move), then you can rebuild it by using the searchindex plugin or bin/indexer.php.

Demo / Screenshots

Changes

Development changelog:

Sites using this Plugin

Feel free to add yours here:

FAQ

How to use tags which consist of multiple words?

Just use an “_”, it gets automatically replaced by a “ ” i.e.:

{{tag>tag_with_multiple_words}}

Also, quotes seem to work:

{{tag>"tag with multiple words"}}

Change CSS styles depending on existing tags

This colors the background of the page to red if the keyword 'deprecated' is specified as a tag.

function _handle_keywords(&$data) {
        global $ID;
 
        // Fetch tags for the page; stop proceeding when no tags specified
        $tags = p_get_metadata($ID, 'subject', METADATA_DONT_RENDER);
        if(is_null($tags)) true;
 
        // Replace underscores with blanks
        foreach($data->data['meta'] as &$meta) {
            if($meta['name'] == 'keywords') {
                $meta['content'] = str_replace('_', ' ', $meta['content']);
 
                $t = explode(',', $meta['content']);
                if(in_array('deprecated', $t)) {
                    $data->data['style'][] = array('type'  => 'text/css',
                                                     '_data' => '.dokuwiki .page {background-color: red;}');
                }
            }
        }       
}

Customizing the breadcrumbs

If you add at pagelist/helper.php

function tpl_youarehere2_help($id){
    $result = '';
    global $conf;
    global $ID;
    global $lang;
    // check if enabled
    if(!$conf['youarehere']) return false;
    $parts = explode(':', $id);
    $count = count($parts);
    // always print the startpage
    $result .= html_wikilink(':'.$conf['start']);
    // print intermediate namespace links
    $part = '';
    for($i=0; $i<$count - 1; $i++){
        $part .= $parts[$i].':';
        $page = $part;
        if ($page == $conf['start']) continue; // Skip startpage
        // output
        $result .= ' &raquo '.html_wikilink($page);
    }
    // print current page, skipping start page, skipping for namespace index
    resolve_pageid('',$page,$exists);
    if(isset($page) && $page==$part.$parts[$i]) return $result;
    $page = $part.$parts[$i];
    if($page == $conf['start']) return $result;
    $result .= ' &raquo '.html_wikilink($page);
    return $result;
}
 
function tpl_youarehere2($id) {
    $str = $this->tpl_youarehere2_help($id);
    $pos = strrpos($str , '&raquo');
    if ($pos == -1)
    return $str;
    return substr($str, 0, $pos);
}
 
function addPage2($page) {
    $id = $page['id'];
    if (!$id) return false;
    $this->page = $page;
    $this->_meta = NULL;
    // priority and draft
    if (!isset($this->page['draft'])) {
        $this->page['draft'] = ($this->_getMeta('type') == 'draft');
    }
    $class = '';
    if (isset($this->page['priority'])) $class .= 'priority'.$this->page['priority']. ' ';
    if ($this->page['draft']) $class .= 'draft ';
    if ($this->page['class']) $class .= $this->page['class'];
    if(!empty($class)) $class = ' class="' . $class . '"';
    $this->doc .= DOKU_TAB.'<tr'.$class.'>'.DOKU_LF;
    $this->_pageCell($id);
    if ($this->column['date']) $this->_dateCell();
    if ($this->column['user']) $this->_userCell();
    if ($this->column['desc']) $this->_descCell();
    foreach ($this->plugins as $plug => $col) {
        if ($this->column[$col]) $this->_pluginCell($plug, $col, $id);
    }
    $this->doc .= DOKU_TAB.'</tr>'.DOKU_LF;
    $this->doc .= DOKU_TAB.'<tr'.$class.'>'.DOKU_LF;
    $this->doc .= DOKU_TAB.DOKU_TAB.'<td style="padding-left:19px; padding-right:15px; padding-bottom:15px; font-size:10px;">';
    $this->doc .= $this->tpl_youarehere2($id);
    $this->doc .='</td>'.DOKU_LF;
    $this->doc .= DOKU_TAB.'</tr>'.DOKU_LF;
    return true;
}

And change tag/action.php

$pagelist->setFlags($flags);
$pagelist->startList();
foreach ($pages as $page) {
    $pagelist->addPage($page);
}

to

$pagelist->setFlags($flags);
$pagelist->startList();
foreach ($pages as $page) {
    $pagelist->addPage2($page);
}

After that, the list of pages that contain the tag, except for the names of pages themselves under them will also be bread crumbs to these pages.

Bad appearance when displaying tags at top of page

:!: Integrated to main code (see tags_list_css) option

When you insert the syntax at the top of a wiki page, the output of the plugin will be displayed below the TOC (Table of Contents). To make the visual appearance more smooth, change your lib/plugins/tag/style.css to the following code:

div.dokuwiki div.tags {
  border-top: 2px dotted __border__;
  font-size: 95%;
  text-align: right;
/*  clear: both; */
}

How to change the word tag and topic to another language

Is it possible to change the word tag used in syntax to something else, like another language {{tagInMylanguage>someTag}} –damascenedamascene

2012/04/10

Discussion

I want the description under the tag, is it possible to make a line brake or to get the description under the tag? Thx

Is there any tip for hierarchical tag? I try to categorize my pages. For example, there are two pages. A Persian cat page has {tag>animal:cat}. And a Dalmatian dog page has {tag>animal:dog}. If I write '{topic>animal}, I hope to see the two pages, but all I can see is blank. Yes, I can tag that {tag>animal dog}, {tag>animal cat}, but it is not fancy.

How do I tag a page? Lots of detail about how to display tagged pages, but I cannot find anything about how to tag a page to begin with.

You have to type it into the page. Look at the Components portion of this page to see what to type.

For bugs or feature requests, there is the bug tracker linked here : Bug tracker.

This plugin clashes with the include module of the mediasyntax plugin. One workaround is to disable that part of the mediasyntax plugin by renaming the include.php file.

If you have a tag name that is the same as a page name that already exists, the tag links will point to that page in the current namespace rather than the page name in the tag namespace. Is this a bug or a feature? (3-Aug-2011)?

Found the issue. If you do not specify a namespace, it defaults to whatever is defined as the default namespace (ie. root:tag). If you do specify a namespace, it makes whatever you specify as the location for the data file (ie. root:mynamespace), NOT root:tag:mynamespace.

My wiki has about 7000 pages with tags. It takes 25 seconds to display ~~TAGCLOUD~~ (My server runs with latest NGINX, UBUNTU 12.04, 4 core i5 cpu with 8gb ram, intel SSD ). Anyone have any other suggestion? or Do I need SQL-based tagging solution? — S.C. YooS.C. Yoo
goldseed

2014/04/19 06:02

Individual Search Form: I'd like a form where the user could just type in the tag name, click search, and then a list is generated below. I know you got the searchtags but its just going to get unwieldy with the amount of tags I'm envisioning having. Thanks

Structured Tags: Can this (or any other plugin) support structured tags in addition to free-form tags? – 2014-09-02

Blank pages

I'm using Dokuwiki under Debian, last version in Debian distro. I installed plugin tags, but don't work :(

All page with {{tag>name_tag}} results a blank page, including the content of the page. I don't know what don't work but, I can't use it :(

I am using Debian Wheezy and I am having the same issue.

»»»»» Hy, I think the tag should be separted by a “,”. I mean what happen if I wanna tag “New York City” ? In present is created separte tag for “new” “york” “city” and that's not really good. — A.Vadrianvesa

Nothing was found.

Same here, get a Nothing was found page.

(2017-03-28) I had the same problem. By coincidence, I switched to the default Dokuwiki template for an unrelated reason and got a different error when I clicked a tag link: “Helper plugin pagelist is not available.” Installed the pagelist plugin and then it worked. This dependency needs to be documented.

SEO meta keywords

Does this plugin alter the meta tags of the rendered pages? If it doesn't, I would like to leave the suggestion. — Fabricio RochaFabricio Rocha

2016-06-11 17:00

Sorting the {{count>}} results

Is there any way to sort the output of the {{count>}} command? I'd like to have a page of used tags in alphabetical order, but it seems that pagelist parameters are not supported. — Fabricio RochaFabricio Rocha

2016-06-19 19:42

Unorderd List of all tags?

Is there a way to gen an unorderd list of all tags, similar as search?q=%2B&amp;btnI=lucky, but without table and occurrences?