Blog with multiple categories

Hi everyone,
I’m happy to join the grav community.
I already have a blog based on hugo and I want to migrate to grav, but I can’t find the right way to do it :sweat_smile: .
So, I have three links on the main menu (apart from about and contact page) that are for three categories. Clicking on one of them will list all the posts belonging to that category. Some posts belong to more than one.
I tried to use taxonomy but I didn’t find the right way to get it done in the docs.
I’m using darkquark theme then I created a new page with blog layout and some children items. I end up with one link in the menu and all the posts on the same page.
Thanks for the help

@miro5001, I think the question would be easier/better to understand if you provide more concrete information like:

  • What’s your file structure (the relevant part of it).
    You could use $ tree user/pages | clip or $ tree user/pages | clip.exe to get a nice tree. Then paste it between triple backticks.
  • The frontmatter of a page that shows a single category
  • How you’ve created and used taxonomies
  • What you expect from taxonomies
  • What doesn’t work with taxonomies

To see how blogs and taxonomies work, you might want to download the Blog Site skeleton. It provides a complete working blog site using taxonomies.

1 Like

I’m sorry, I’ve been overwhelmed by work.
I’ve installed grav using softaculous on a shared host and another instance using yunohost (selfhosted at home).
I had little time on pc, that’s why I was looking for something that can be managed by phone.
I have downloaded the blog skeleton and uploaded it to the shared host and will install it tonight. (it would have been easier to get the skeleton right from the admin interface).
Thanks for helping, I’ll report back soon.

OK, that was fast.
The blog skeleton isn’t really what I was looking for.

So, suppose we have 5 posts in three categories :

  • Post1 (photography, health)
  • Post2 (photography, technology)
  • Post3 (health)
  • Post4 (education)
  • Post5 (technology, education)

What I wanted is to have links in the main menu for each category. When I click on “photography”, all posts in this category are listed in blog mode. And the same for the others. Note that a post can belong to more than one category.

@miro5001, The Blog Site skeleton gives you a quick idea how blogs and taxonomy work together in Grav using the Taxonomylist plugin in the sidebar. That might not be what you’re used to or what you want, but that’s the easy way that works out-of-the-box.

If you want to mimic the Taxonomylist as a menu, you’ll have to code that yourself by altering the template that generates the menu. The menu should then contain a mix of links with parameters like the links generated by the Taxonomylist plugin and links to pages like Contact and About.

@miro5001 , yes, it works just like @pamtbaau described - my own website has an example for a link in main menu that provides a list of blog items for a given category, in this case 'EDV:
here is the code for the page template category.html.twig:

{% embed 'partials/base.html.twig' %}

	{% set collection = page.collection() %}
	{% set base_url = page.url %}
	{% set feed_url = base_url %}

	{% if base_url == '/' %}
		{% set base_url = '' %}
	{% endif %}

	{% if base_url == base_url_relative %}
		{% set feed_url = base_url~'/'~page.slug %}
	{% endif  %}

	{% block content %}
		{# Link Post URLs from category EDV only, see Docu #}
        <h2 class="archiv">Blog Archiv der Kategorie EDV</h2>
    	<div class="toggle-button hamburger {{ config.theme.hamburger_animation }}">
			<div class="hamburger-box">
				<div class="hamburger-inner"></div>
		<div class="archiv">
		{% for post in taxonomy.findTaxonomy({'category':'EDV'}).order('date','desc') %}
			{{|date('d.m.Y') }} - <a href="{{ post.url }}">{{ post.title }}</a><br>
		{% endfor %}
		{% if config.plugins.pagination.enabled and collection.params.pagination %}
			{% include 'partials/pagination.html.twig' with {'pagination':collection.params.pagination} %}
		{% endif %}
	{% endblock %}

{% endembed %}

1 Like

So I managed to get what I was looking for.

  1. Create a new page
  2. Name it the same as the category name (exemple ‘photography’)
  3. Go to Advanced > overrides > page redirect and enable it
  4. The redirect link will be ‘
  5. Save it

Now I have a new item in the main menu which lists all posts of a defined category. The same can be done for tags, replacing ‘category’ with ‘tag’.

Thanks everyone for helping me

Edit: category name is case sensitive

1 Like