Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to filter from a specific page. #20

Merged
merged 1 commit into from
Apr 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public function onTwigSiteVariables()
$filters = (array) $this->config->get('plugins.archives.filters');
$operator = $this->config->get('plugins.archives.filter_combinator');
$new_approach = false;
$page_approach = false;
$collection = null;

if ( ! $filters || (count($filters) == 1 && !reset($filters))){
Expand All @@ -133,6 +134,8 @@ public function onTwigSiteVariables()
// see if the filter uses the new 'items-type' syntax
if ($key === '@self' || $key === 'self@') {
$new_approach = true;
} elseif ($key === '@page' || $key === 'page@') {
$page_approach = true;
} elseif ($key === '@taxonomy' || $key === 'taxonomy@') {
$taxonomies = $filter === false ? false : array_merge($taxonomies, (array) $filter);
} else {
Expand All @@ -141,6 +144,8 @@ public function onTwigSiteVariables()
}
if ($new_approach) {
$collection = $page->children();
} elseif ($page_approach) {
$collection = $pages->find($filter)->children();
} else {
$collection = new Collection();
$collection->append($taxonomy_map->findTaxonomy($find_taxonomy, $operator)->toArray());
Expand All @@ -150,6 +155,8 @@ public function onTwigSiteVariables()
// reorder the collection based on settings
$collection = $collection->order($this->config->get('plugins.archives.order.by'), $this->config->get('plugins.archives.order.dir'));
$date_format = $this->config->get('plugins.archives.date_display_format');
// drop unpublished and unroutable pages
$collection->published()->routable();

// loop over new collection of pages that match filters
foreach ($collection as $page) {
Expand Down