You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//Gets the input into a two dimensional array - uses '~' as separator;
21
26
foreach ($parentas$item){
@@ -26,7 +31,7 @@ function alphabetise($parent, $options=array()) {
26
31
}
27
32
28
33
// Check to see array is not empty
29
-
if ( (!empty ($array)) ) {
34
+
if ( (!empty ($array)) ) {
30
35
//Make an array of key and data
31
36
foreach ($arrayas$temp => $item){
32
37
if (strlen($temp)<2){
@@ -35,21 +40,21 @@ function alphabetise($parent, $options=array()) {
35
40
} else {
36
41
$array[substr($temp, 0, 1)][]=$item[0];
37
42
}
38
-
unset ($array[$temp]);
43
+
unset ($array[$temp]);
39
44
}
40
45
41
46
// If all OK $array will be returned and sorted
42
-
ksort($array);
43
-
47
+
ksort($array,$options['orderby']);
48
+
44
49
} else {
45
-
50
+
46
51
// There has been a problem so set $array with error message and then return $array
47
52
$array = array(
48
53
"Alphabetise Plugin Error: Problem with array or invalid key!
49
54
Make sure your array is valid, not empty & that the key is valid for this type of array. (You can probably ignore the errors after this point, until this error has been resolved.)" => "Error"
Copy file name to clipboardExpand all lines: readme.mdown
+30-8Lines changed: 30 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,13 @@
2
2
3
3
## What is it?
4
4
5
-
The Alphabetise plugin will alphabetise a given [Kirby CMS](http://getkirby.com/)*page* array or *tag* array and return it for further processing/display as an alphabetised array.
5
+
The Alphabetise plugin will alphabetise a given [Kirby CMS](http://getkirby.com/)*page* array or *tag* array and return it for further processing/display as an alphabetised array.
6
6
7
-
*The array whose key your are trying to sort on should of course only contain letters of the alphabet, if not problems may occur.*
7
+
*The array whose key your are trying to sort on should of course only contain letters of the alphabet, if not problems may occur.*
8
8
9
9
*Also the code (explode) uses a '~' tilde, if you use this in your key, especially at the beginning of the string, then you could run into sorting problems. You could of course manually change it if required.*
10
10
11
-
## Installation
11
+
## Installation
12
12
13
13
Put all the files into your **site/plugins/alphabetise** folderor use the [Kirby CLI](https://github.com/getkirby/cli): In your project folder, from the command line, enter:
The first argument you pass is the sorted **page** array you want to *alphabetise*. The second array **key** argument is so you can set what you want to *alphabetise* by. It should be a string like a page 'title'. The 'sortby' and the 'key' should usually be the same.
37
+
The first argument you pass is the sorted **page** array you want to *alphabetise*. The second array **key** argument is so you can set what you want to *alphabetise* by. It should be a string like a page 'title'. The 'sortby' and the 'key' should usually be the same.
38
38
39
39
You then want to loop through the returned results and display them for example:
40
40
```php
@@ -47,13 +47,13 @@ You then want to loop through the returned results and display them for example:
47
47
<?php echo $item->title()?>
48
48
</a>
49
49
</li>
50
-
<?php endforeach ?>
50
+
<?php endforeach ?>
51
51
</ul>
52
52
<hr/>
53
53
<?php endforeach ?>
54
54
```
55
55
56
-
####Example2: Alphabetical list of tags using tag name as the key
56
+
####Example2: Alphabetical list of tags using tag name as the key
57
57
58
58
#####A
59
59
+ Aa tag
@@ -102,7 +102,29 @@ You can use any valid array element, so for tags you can use also add **$item->r
102
102
</li>
103
103
```
104
104
105
-
105
+
####Example3: Set 'orderby' key
106
+
107
+
Version 0.0.9 adds a key to alter how the array appears, the default is with letters and then numbers e.g.
108
+
109
+
+ A
110
+
+ B
111
+
+ 1
112
+
+ 2
113
+
114
+
Or you can not set the 'orderby' key to SORT_STRING, to have the numbers listed first e.g.
0 commit comments