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
This is a category extension documentation initiation.
This extension enables the category filter feature by using the page’s kind property to add multiple routes, such as https://127.0.0.1/blog/category/:category/1, to each page to allow users to list all pages in the current folder by category.
Panel extension can help you to automate everything. But if you have to, you can still make this extension work without the GUI feature. Before we start, you need to know how this extension works.
Writing a category file is the same as writing a page file. The only difference is that you have to write the id property separately from the page. Be sure to specify a unique number for each id.data file. These numbers will then be used to associate the category file with the kind property on each page:
Here’s an example of what a category file might contain:
---
title: Category Namedescription: Short description about this category.type: Markdown
...
Long description about this category.
To associate categories with the current page, create a kind.data file in the relevant folder that contains a list of category IDs written in a valid JSON format:
Unlike tags, category IDs are written as a float to represent parent-child relationship because categories can also have several other associated sub-categories. Digits before the period denote the parent category ID, and digits after the period denote the current category ID. Category ID with prefix 0. denotes a category without a parent. Therefore, ID 0 should not be used. You should create a category ID starting with the number 1. Other integer values will be considered as tag IDs.
You can also include the kind property in the page header, but this method may not be performance efficient when reading the data:
These HTML classes will be added to the root element if it contains a class attribute when you are on the categories 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:category
: Will be added if the current items view is a category view and is not empty.
Example usage in CSS code:
.is\:categorybody {
border-top:4px solid #f00;
}
Example usage in JS code:
if(document.documentElement.classList.contains('is:category')){console.info('You are currently in the category page.');}
These additional conditional statements are available for use in layouts to show/hide elements on your site from the server side:
$site->is('category')
: Returns true if the current items view is a category view and is not empty.
Example usage in HTML/PHP code:
<?phpif ($site->is('category')): ?>
<p role="alert">
<?=i('You are currently in the category page.'); ?>
</p>
<?phpendif; ?>
These additional variables are available for use in layouts that carry data related to the currently active category page:
$category
: This variable is an instance of the Category class, which you can use to get the current category information.
This extension will also add category property to the page only if the page contains a kind property that
is not empty:
// These numbers refer to the category and tag IDs.$kind = $page->kind; // Returns `[1, 2, 3, 0.1, 2.3, 4.5]`// This category data are also generated based on the available categories.$tags = $page->category; // Returns `Category` class instance
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
This is a category extension documentation initiation.
This extension enables the category filter feature by using the page’s
kind
property to add multiple routes, such ashttps://127.0.0.1/blog/category/:category/1
, to each page to allow users to list all pages in the current folder by category.Panel extension can help you to automate everything. But if you have to, you can still make this extension work without the GUI feature. Before we start, you need to know how this extension works.
Writing a category file is the same as writing a page file. The only difference is that you have to write the
id
property separately from the page. Be sure to specify a unique number for eachid.data
file. These numbers will then be used to associate the category file with thekind
property on each page:Here’s an example of what a category file might contain:
To associate categories with the current page, create a
kind.data
file in the relevant folder that contains a list of category IDs written in a valid JSON format:Example contents of a
kind.data
file:Unlike tags, category IDs are written as a float to represent parent-child relationship because categories can also have several other associated sub-categories. Digits before the period denote the parent category ID, and digits after the period denote the current category ID. Category ID with prefix
0.
denotes a category without a parent. Therefore, ID0
should not be used. You should create a category ID starting with the number1
. Other integer values will be considered as tag IDs.You can also include the
kind
property in the page header, but this method may not be performance efficient when reading the data:Sub-categories are stored as child pages. This allows sub-categories to have the same name with a different parent page name:
Category child routes will then be available as follows:
Usage
These HTML classes will be added to the root element if it contains a
class
attribute when you are on the categories 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:category
: Will be added if the current items view is a category view and is not empty.
Example usage in CSS code:
Example usage in JS code:
These additional conditional statements are available for use in layouts to show/hide elements on your site from the server side:
$site->is('category')
: Returns
true
if the current items view is a category view and is not empty.Example usage in HTML/PHP code:
These additional variables are available for use in layouts that carry data related to the currently active category page:
$category
: This variable is an instance of the
Category
class, which you can use to get the current category information.Example usage in HTML/PHP code:
This extension will also add
category
property to the page only if the page contains akind
property thatis not empty:
Example usage in HTML/PHP code:
Beta Was this translation helpful? Give feedback.
All reactions