Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

How to display taxonomies-category in blog menu?

Started by Muut Archive 10 years ago · 3 replies · 1866 views
10 years ago

Hi!

I would like to display categories in my blog's menu to list all posts of category , but i don't found something with indications of how to do.

Por exemplo:

  • Home
  • Lifestyle (taxonomy category 1)
  • Sports (taxonomy category 2)
  • Culture (taxonomy category 3)
  • About
  • Contact

Thanks for any help! ;)

10 years ago

The navigation is built by twig like any other template. You can use taxonomy.findTaxonomy() (see the docs) when building your menu just as you could anywhere else.

10 years ago

Hi Perlkönig,
I'm starting at the grav and did not know how to start, but I found a post[1] that indicates to install the "taxonomylist" plugin and add the following snippet at the end of the code that renders the navigation menu:

navigation.html.twig

TWIG
{% set taxlist = taxonomylist.get() %}
{% if taxlist %}
  {% set category = grav.uri.params("category", true) %}
  {% for tax,value in taxlist['category'] %}
  {% set current_page = (tax == category) ? 'active' : '' %}
  <li class="{{ current_page }}">
    <a href="{{ base_url }}/category{{ config.system.param_sep }},{{ tax|e('url') }}">{{ tax|capitalize }}</a>
  </li>
  {% endfor %}
{% endif %}

It works, but need a few adjustments. ;)

[1] http://diblas.net/blog/add-the-posts-categories-to-the-blog-navigation-menu-powered-by-grav-cms

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1357 9 years ago
Archive · by Muut Archive, 9 years ago
2 936 9 years ago
Archive · by Muut Archive, 9 years ago
2 4066 9 years ago
Archive · by Muut Archive, 9 years ago
1 2954 9 years ago
Archive · by Muut Archive, 9 years ago
3 1120 9 years ago