This extension enables the time filter feature by using the page’s time
property to add multiple routes, such as http://127.0.0.1/blog/archive/:archive/1
, to each page to allow users to list all pages in the current folder by time.
As a note, every time you want to link a page to a specific year-based archive, be sure to add the pagination offset to the end of the URL to prevent Mecha from misinterpreting the archive query as a pagination offset or individual page name:
http://127.0.0.1/blog/archive/2020 ✘
http://127.0.0.1/blog/archive/2020/1 ✔
http://127.0.0.1/blog/archive/2020-09 ✘
http://127.0.0.1/blog/archive/2020-09/1 ✔
http://127.0.0.1/blog/archive/2020-09-18 ✘
http://127.0.0.1/blog/archive/2020-09-18/1 ✔
Usage
These HTML classes will be added to the root element if it contains a class
attribute when you are on the archives page. You can use this feature to create a specific look or response on your site from the client side if the following classes are found in the root element:
is:archives
- Will be added if the current items view is an archives view and is not empty.
Example usage in CSS code:
.is\:archives body {
border-top: 4px solid #f00;
}
Example usage in JS code:
if (document.documentElement.classList.contains('is:archives')) {
console.info('You are currently in the archives page.');
}
These additional conditional statements are available for use in layouts to show/hide elements on your site from the server side:
$site->is('archives')
- Returns
true
if the current items view is an archives view and is not empty.
Example usage in HTML/PHP code:
<?php if ($site->is('archives')): ?>
<p role="alert">
<?= i('You are currently in the archives page.'); ?>
</p>
<?php endif; ?>
These additional variables are available for use in layouts that carry data related to the currently active archives page:
$archive
- This variable is an instance of the
Time
class, which you can use to get the archive time portion of the URL.
Example usage in HTML/PHP code:
<?php if ($site->is('archives') && !empty($archive)): ?>
<p role="alert">
<?= i('Showing archives back in year %d.', $archive->year); ?>
</p>
<?php endif; ?>
0 Comments
No comments yet.