-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtagnavi.php
73 lines (69 loc) · 3.15 KB
/
tagnavi.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
class YellowTagNavi
{
const VERSION = "0.9.06";
public $yellow; // access to API
// Handle initialisation
public function onLoad($yellow)
{
$this->yellow = $yellow;
}
// Return a blogtag navigation
public function getTagNavi($startLocation, $tagCount, $entriesMax, $class, $filterName, $url, $urlArg)
{
$output = null;
$blogStart = $this->yellow->content->find($startLocation);
$pages = $this->yellow->content->index()->filter("layout", "blog")->sort("published", false);
$tags = $pages->group("tag"); // = group content by tag with ascending name, A-Z
// $tags = $pages->group("tag", false); // = group content by tag with descending name, Z-A
// $tags = $pages->group("tag", false, "count"); // = group content by tag with descending count, highest first
$url = $url.$startLocation.$urlArg;
$numberAllPosts = "";
$numberPosts = "";
if (strpos($urlArg, "age:")) {
$pageNr = explode("page:", $urlArg);
$urlPagination = "page:" . $pageNr[1];
} else{
$urlPagination = "";
}
if (!is_array_empty($tags)) {
if ($tagCount == "count"){
$countPosts = 0;
foreach ($pages as $page) {
$countPosts++;
}
$numberAllPosts = "<span>" . $countPosts . "</span>";
}
if ($entriesMax != 0 && count($tags) > $entriesMax) {
$tags = array_slice($tags, -$entriesMax, $entriesMax, true);
}
$output = "<nav class=\"" . htmlspecialchars($class) . "\">\n";
$output .= "<ul>\n";
if ($url == $blogStart->getLocation(true). $urlPagination){
$output .= "<li><a class=\"active\" aria-current=\"page\" href=\"" . $blogStart->getLocation(true) . "\">";
$output .= htmlspecialchars($filterName) . "</a>" . $numberAllPosts . "</li>\n";
}else{
$output .= "<li><a href=\"" . $blogStart->getLocation(true) . "\">";
$output .= htmlspecialchars($filterName) . "</a>" . $numberAllPosts . "</li>\n";
}
foreach ($tags as $key => $value) {
if ($tagCount == "count"){
$numberPosts = "<span>" . count($value) . "</span>";
}
$urlNavi = $blogStart->getLocation(true) . $this->yellow->lookup->normaliseArguments("tag:$key");
if ($url == $urlNavi.$urlPagination){
$output .= "<li><a class=\"active\" aria-current=\"page\" href=\"" . $urlNavi . "\">";
$output .= htmlspecialchars($key) . "</a>" . $numberPosts . "</li>\n";
} else {
$output .= "<li><a href=\"" . $urlNavi . "\">";
$output .= htmlspecialchars($key) . "</a>" . $numberPosts . "</li>\n";
}
}
$output .= "</ul>\n";
$output .= "</nav>\n";
} else {
$output = "The location of your blog start page is wrong (/ or /blog/ or ...)";
}
return $output;
}
}