<?php /** * Tagunslag Plugin * * @author Marijn Tijhuis <*****@*****.**> * @version 1.0.0 */ // Field method field::$methods['tagunslug'] = function ($field) { $field->value = tagunslug($field); return $field; }; // Convert tag slug (see tagslug plugin) string to tag name function tagunslug($text) { // uppercase first character after -and- $text = implode('-and-', array_map('ucfirst', explode('-and-', $text))); // replace -and- by <space>&<space> $text = str_replace('-and-', ' & ', $text); // replace - buy <space> $text = str_replace('-', ' ', $text); // uppercase $text = ucfirst($text); return $text; }
<?php /////////////////////////////////////////////////////// // ---------------------------------------------------------- // SNIPPET // ---------------------------------------------------------- // If there is a param in the url if (param()) { // Get the first key of the param array, but when the first key in url is `tag` (singular), make sure to use `tags` (plural; used in the text files) as the key value! $paramkey = key(param()) == 'tag' ? 'tags' : key(param()); // Unslug the param to a tag $paramvalue = tagunslug(param(key(param()))); // Save param and tag for use in URL $paramurl = key(param()) . ':' . param(key(param())); // Filter projects by param $page_items = $page->siblings()->visible()->filterBy($paramkey, $paramvalue, ',')->flip(); $lookup_page = []; $i = 0; // Build an array with all project id's of the filtered projects foreach ($page_items as $page_item) { $lookup_page[$i] = $page_item->id(); $i++; } // return the key of the array where the current page is located $current_page_index = array_search($page->id(), $lookup_page); if (isset($current_page_index)) { // If the current page is not the first of the filtered list if ($current_page_index > 0) { $next_page = page($lookup_page[$current_page_index - 1]); $next_title = $next_page->title(); $next_url = $next_page->url() . '/' . $paramurl;