Commit 053c1da 0 parents commit 053c1da Copy full SHA for 053c1da
File tree 3 files changed +53
-0
lines changed
3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ # TaxonomyFilter for Statamic (v2)
2
+
3
+ Filter a collection based on entries' arrays of taxonomy IDs.
4
+
5
+ ## Installation
6
+
7
+ 1 . Move the ` statamic-TaxonomyFilter ` folder to ` site/addons/TaxonomyFilter ` (removing the ` statamic- ` bit)
8
+ 2 . ` cd ` into your site's directory.
9
+ 3 . Run ` php please addons:refresh `
10
+
11
+ ## Usage
12
+
13
+ In your template, use the filter like this:
14
+
15
+ ```
16
+ {{ collection:collection_slug filter="TaxonomyFilter" tf_group="{ taxonomy_group_slug }" tf_slug="{ taxonomy_item_slug }" }}
17
+ ```
18
+
19
+ If ` tf_slug ` is not provided, it defaults to the value of ` {{ last_segment }} ` .
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Statamic \Addons \TaxonomyFilter ;
4
+
5
+ use Statamic \Extend \Filter ;
6
+ use Statamic \API \TaxonomyTerm ;
7
+
8
+ class TaxonomyFilterFilter extends Filter
9
+ {
10
+ /**
11
+ * Filter a collection based on entries' arrays of taxonomy IDs
12
+ *
13
+ * @return \Illuminate\Support\Collection
14
+ */
15
+ public function filter ()
16
+ {
17
+ return $ this ->collection ->filter (function ($ entry )
18
+ {
19
+
20
+ $ tf_slug = $ this ->get ('tf_slug ' ,$ this ->context ['last_segment ' ]);
21
+ $ taxonomy_object = TaxonomyTerm::getFromTaxonomy ($ this ->get ('tf_group ' ),$ tf_slug );
22
+ $ the_id = $ taxonomy_object ->get ('id ' );
23
+
24
+ return in_array ($ the_id ,$ entry ->get ($ this ->get ('tf_group ' )));
25
+
26
+ });
27
+ }
28
+ }
Original file line number Diff line number Diff line change
1
+ name : TaxonomyFilter
2
+ version : 1.0
3
+ description : Filter a collection based on entries' arrays of taxonomy IDs.
4
+ url : https://github.com/chris-79/statamic-TaxonomyFilter
5
+ developer : Chris S.
6
+ developer_url : https://github.com/chris-79
You can’t perform that action at this time.
0 commit comments