Taxonomy
in package
The Taxonomy object is a singleton that holds a reference to a 'taxonomy map'. This map is constructed as a multidimensional array.
uses the taxonomy defined in the site.yaml file and is built when the page objects are recursed. Basically every time a page is found that has taxonomy references, an entry to the page is stored in the taxonomy map. The map has the following format:
[taxonomy_type][taxonomy_value][page_path]
For example:
[category][blog][path/to/item1] [tag][grav][path/to/item1] [tag][grav][path/to/item2] [tag][dog][path/to/item3]
Table of Contents
Properties
- $grav : Grav
- $language : Language
- $taxonomy_map : array<string|int, mixed>
Methods
- __construct() : mixed
- Constructor that resets the map
- addTaxonomy() : mixed
- Takes an individual page and processes the taxonomies configured in its header. It then adds those taxonomies to the map
- findTaxonomy() : Collection
- Returns a new Page object with the sub-pages containing all the values set for a particular taxonomy.
- getTaxonomyItemKeys() : array<string|int, mixed>
- Gets item keys per taxonomy
- iterateTaxonomy() : void
- Iterate through taxonomy fields
- taxonomy() : array<string|int, mixed>
- Gets and Sets the taxonomy map
Properties
$grav
protected
Grav
$grav
$language
protected
Language
$language
$taxonomy_map
protected
array<string|int, mixed>
$taxonomy_map
Methods
__construct()
Constructor that resets the map
public
__construct(Grav $grav) : mixed
Parameters
- $grav : Grav
addTaxonomy()
Takes an individual page and processes the taxonomies configured in its header. It then adds those taxonomies to the map
public
addTaxonomy(PageInterface $page[, array<string|int, mixed>|null $page_taxonomy = null ]) : mixed
Parameters
- $page : PageInterface
-
the page to process
- $page_taxonomy : array<string|int, mixed>|null = null
findTaxonomy()
Returns a new Page object with the sub-pages containing all the values set for a particular taxonomy.
public
findTaxonomy(array<string|int, mixed> $taxonomies[, string $operator = 'and' ]) : Collection
Parameters
- $taxonomies : array<string|int, mixed>
-
taxonomies to search, eg ['tag'=>['animal','cat']]
- $operator : string = 'and'
-
can be 'or' or 'and' (defaults to 'and')
Return values
Collection —Collection object set to contain matches found in the taxonomy map
getTaxonomyItemKeys()
Gets item keys per taxonomy
public
getTaxonomyItemKeys(string $taxonomy) : array<string|int, mixed>
Parameters
- $taxonomy : string
-
taxonomy name
Return values
array<string|int, mixed> —keys of this taxonomy
iterateTaxonomy()
Iterate through taxonomy fields
public
iterateTaxonomy(PageInterface $page, string $taxonomy, string $key, iterable<string|int, mixed>|string $value) : void
Reduces [taxonomy_type] to dot-notation where necessary
Parameters
- $page : PageInterface
-
The Page to process
- $taxonomy : string
-
Taxonomy type to add
- $key : string
-
Taxonomy type to concatenate
- $value : iterable<string|int, mixed>|string
-
Taxonomy value to add or iterate
taxonomy()
Gets and Sets the taxonomy map
public
taxonomy([array<string|int, mixed>|null $var = null ]) : array<string|int, mixed>
Parameters
- $var : array<string|int, mixed>|null = null
-
the taxonomy map
Return values
array<string|int, mixed> —the taxonomy map