<?php $i = 0; $tags = str::split($page->tags(), ","); $tag_type = '/events/type-'; foreach ($tags as $tag) { ?> <a href="<?php echo $site->url() . $tag_type . tagslug($tag); ?> "><?php echo $tag; ?> </a> <?php if ($i < count($tags) - 1) { echo ', '; } ?> <?php $i++; }
<?php /** * Tagslag Plugin * * @author Marijn Tijhuis <*****@*****.**> * @version 1.0.0 */ // Field method field::$methods['tagslug'] = function ($field) { $field->value = tagslug($field); return $field; }; // Convert tag name to slug (url) function tagslug($text) { // replace & by -and- $text = str_replace('&', '-and-', $text); // replace non letter or digits by - $text = preg_replace('~[^\\pL\\d]+~u', '-', $text); // trim $text = trim($text, '-'); // transliterate $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text); // lowercase $text = strtolower($text); // remove unwanted characters $text = preg_replace('~[^-\\w]+~', '', $text); if (empty($text)) { return 'n-a'; }