Documentation

Light-weight, fast, simple and powerful!
 
Translations of this page?:

tags()

tags() produces an array of the tags which have been entered in the “tags” field under the Metadata tab when editing a page.

Usage

Wolf's default installation gives a simple demonstration of a list of tags in the “Articles” page, where the following line is included:

tags: <?php echo join(', ', $article->tags()); ?>

This shows you how to turn the tags() array into string, and this can then be used for other purposes.

Plugin

The most obvious way of handling tags is by using the Tagger plugin which is under active development. Its growing feature set allows for a range of tag-management and usage options.

Examples

Subpages filtered by tag

If you wanted to give the list of subpages to a parent page, based on the presence of a particular tag, you could do it this way:

<?php $findTag = 'hello'; // REPLACE hello WITH THE TAG YOU WANT TO FIND ?>
<h3>Pages with the tag "<?php echo $findTag; ?>":</h3>
<ul>
<?php foreach ($this->children() as $child): ?>
<?php $childTags = join(',', $child->tags()); ?>
  <?php if (strpos($childTags, $findTag) !== FALSE) : ?>
    <li><?php echo $child->link(); ?></li>
  <?php endif; ?>
<?php endforeach; ?>
</ul>

You manually enter the tag you want to find (“hello” is used in the example above), which is echoed in a heading to your list of pages. Then the foreach loop finds the child pages, while the strpos test filters those pages with the desired tag, which is then output to an unordered list. Include that block of code on the parent page, ensuring that the page's text filter is not TinyMCE, which does not cope with PHP!

Although this code is for use on a “parent” page to find a certain tag-term among its child pages, it could be modified to look in other “branches” of the site, or to look through deeper levels.

 
functions/tags.txt · Last modified: 2012-03-08 11:40 by David
 
Except where otherwise noted, content on this wiki is licensed under the following license:GNU Free Documentation License 1.2
Copyright 2010 wolfcms.org / design by yello studio / Wolf CMS Inside