A categories plugin for BaunCMS
Install using composer on the commandline:
composer require maccath/baun-categories
Or in composer.json
:
"require": {
"maccath/baun-categories": "1.*",
},
Add the following line to your config/plugins.php
file:
'BaunPlugin\Categories\Categories',
Run the following command inside your project directory:
php baun publish:config maccath/baun-categories
This will create config files inside the config/plugins/maccath/baun-categories
directory, which you may then edit to
your liking.
The following configuration options are available:
title
the title used on the categories list page and in the navigationcategory_url
the path used to access your blog categories, no leading slashexclude_from_nav
(boolean) whether or not to exclude the categories page from the navigation
To add categories to your posts, simply add categories: categoryOne, categoryTwo
to the top of your blog post files.
For example, the following file will create a post with the categories 'volutpat' and 'consectetur':
title: Post 1
categories: consectetur, volutpat
----
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ut vehicula erat. Morbi volutpat posuere auctor.
Vivamus condimentum, purus nec tempus euismod, enim massa blandit est, vel elementum lacus nulla ut sem. Integer
orci libero, rutrum id nisl et, euismod auctor augue.
By default, posts for categories will appear at the following path: /categories/categoryName
. The path used to display
categories can be configured in the configuration file found at config/plugins/maccath/baun-categories/categories.php
Inside your themes directory (typically public/themes/themeName/
), create categories.html
. This file can be
customised to display a list of categories however you like. The following example is the default file contents, which
simply displays an unordered list of categories:
{% extends "layout.html" %}
{% block content %}
<h1>{{ categories_title }}</h1>
<ul>
{% for category in categories %}
<li><a href="{{ category.link }}">{{ category.name }}</a></li>
{% endfor %}
</ul>
{% endblock %}