How do I list a simple list of category and tag references?

Thank you for your replies.

How would you solve my problem if you had it? Maybe I’m going in the wrong direction? And perhaps there is a very obvious decision about which I do not know?

@dydaevskiy If the issue is really insurmountable, I could imagine something like the following:

Label hierarchy
Say we have two pages with frontmatter defined as follows:

Page 1                          Page 2
---                             ---
labels:                         labels:
   - Google                       - Google
      - Analytics                    - Ads
   - Wordpress                    - Wordpres
      - Plugins                      - Plugins
         - Free                          - Pro
                                     - Themes
---                             ---

Then all child arrays of a shared parent could be merged into a tree like:

labelTree = [
   "Google" => [
      "Analytics",
      "Ads"
   ],
   "Wordpress" => [
      "Plugins" => [
         "Free",
         "Pro"
      ],
      "Themes"
   ]
]

At each label node in the tree, it might be handy to also store the path/slug of the each page containing the label. The result should then be stored in cache.

In Twig, this tree could easily be displayed in the sidebar of the blog page.

Filtering blog collection
When a blog is accessed using query parameters like https://mydomain/blog/labels:wordpress,themes, the collection of items in the blog needs to be filtered.
For this, the labelTree must be retrieved from cache and filtered using the parameters provided (wordpress/themes). Only entries found with the parameters should then be display in the blog.

Disclaimer:
It’s just a wild guess though… But I think my first try would be something along these lines. Did not try a proof of concept and cannot say anything about performance penalties.

Very grateful for your thoughts. I feel for the development and testing of this solution will take me a huge amount of time. :frowning: Perhaps I will postpone the implementation for a couple of weeks. But I will persistently dig in the direction of your thoughts. Thank you again, thank you very much.

PS It is very disappointing that the CMS developers seem like a very simple and well-placed blogging system. But in fact, you need to kill just not a probable amount of time to get what almost all CMS has by default. I’m just mad at my helplessness. The rest of Grav is beautiful. :slight_smile:

Please forgive me, I can not understand exactly where and how I need to declare:

labelTree = [
   "Google" => [
  "Analytics",
  "Ads"
   ],
   "Wordpress" => [
  "Plugins" => [
     "Free",
     "Pro"
  ],
  "Themes"
   ]
]

That labelTree would be the result of some logic in PHP. During a loop through all pages in the blog, the labels of each page are being merged together into a single labelTree.

@dydaevskiy You might have a look at https://github.com/pamtbaau/grav-plugin-labeltree

It is a rough Proof of Concept that seems to be doing what you want, but needs optimisation. I did not do any testing of performance overhead.

No guarantees included…

Very grateful for your time, work and attention to my problem. I am very pleasantly surprised by your quick response and lightning-fast writing of the plugin (and in fact already the second one) for me.

I rarely meet such kind and sympathetic people on the Internet, I just really respect your time and you for your work and responsiveness. Thanks again!

I followed the link:

https://github.com/pamtbaau/grav-plugin-labeltree

and uploaded the plugin to the site in accordance with the instructions you specified.

I put the code in the site widget (because the include insert didn’t work for some reason):

{% macro recurseTree (tree, labels, blog)%}
<ul>
    {% for label in tree.children%}
        <li> <a href = / blog / labels: {{labels == ''? label.name: labels ~ ',' ~ label.name}}> {{label.name}} </a>
            {% if label.children%}
               {{_self.recurseTree (label, labels == ''? label .name: labels ~ ',' ~ label.name, blog)}}
            {% endif%}
        </ li>
    {% endfor%}
</ ul>
{% endmacro%}

{% set labelTree = labeltree.getLabelTree () %}
{% if count (labelTree.children)> 0%}
    {{_self.recurseTree (labelTree, '', blog)}}
{% endif%}
<hr>

I also replaced this part of the code:

<li> <a href = {{blog.url}} / labels: {{labels == ''?

For this:

<li> <a href = / blog / labels: {{labels == ''?

Because with your version of the blog slug it was not displayed, I think it is not significant, but I decided to write about it.

On one of the blog pages, I added the lines you specified (at the very top of the .md page):

labels:
- Label-1
    - Label-11
- Label-2
    - Label-22

After that, the widget appears on the site:

I wasexcited sothat I thought that everything has already worked, but unfortunately when you go to the link, let’s say this:

https://techblog.sdstudio.top/blog/labels:Label-1

Content filtering did not occur on the blog, that is, in fact, the page just reloaded. You can now look at the link click as I left your plugin in active mode on the site.

I also found that there is an error in the formation of sub links:

<ul>
<li>
	<a href="/blog/labels:Label-1" -="" label-11="> Label-1 - Label- 11 </a>
</ li>
<li>
	<a href="/blog/labels:Label-2" -="" label-22="> Label-2 - Label-22 </a>
</ li>
</ ul>

Thank you again very much for your work, if we manage to test and configure the plugin, I am sure it will solve the headache of a huge number of Grav users. And do not underestimate your decision, I’m more than sure that this plugin (in the future) should go with the default Grav.

Thank you again.

PS I really hope that the developers of Grav will pay attention to this topic, I am not the first who faced the impossibility of the “NORMAL” implementation of taxonomies in this forum.

@dydaevskiy Thanks for the feedback. I fixed two issues.

  1. Yaml syntax in frontmatter:
    I noticed a Yaml syntax error in my README.md in the layout of frontmatter. The labels should be defined as:

    ---
    labels:
        - Label-1:          <-- Colon was missing
            - Label-11
        - Label-2:          <-- Colon was missing
            - Label-22
    ---
    
  2. Missing quotes in labeltree.html.twig:
    Also, I fixed the omission of quotes surrounding the value of ‘href’ in the anchors. The browser is forgiving though…

    Note: Quotes are also missing in your adapted code.

’blog.url’ value:
I have tested the code using Quark with the ‘Blog Site’ skeleton. The template ‘labeltree.html.twig’ is added to ‘/user/themes/quark/templates/partials/sidebar.html.twig’ as shown in the README.md.
In this setup, the variable ‘blog’ is known in ‘labeltree.html.twig’ and the correct slug is generated.
Have a look at your own setup. Maybe ‘blog’ is not defined as in the Quark theme and you might try replacing ‘blog’ by ‘page’.

NB. Would you mind adding issues on Github? That’s where ‘issues’ are defined for isn’t it? :wink:

1 Like

Thank you very much, I got exactly what I wanted very long ago. Thanks again!

I think a slightly better solution instead of using a plugin that is not really meant for public use you can just do this following.

Step 1: install Grav TaxonomyList plugin

Step 2: insert this small code snippet. It will give you a list of categories used on your site as well as the count of times it is used.

{% set taxlist = taxonomylist.get() %}
{% if taxlist %}
  <ul>
    {% for tax,value in taxlist['category'] %} 
      <li><a href="{{ base_url }}/category{{ config.system.param_sep }}{{ tax|e('url') }}">{{ tax|title }} ({{ value }})</a></li> 
    {% endfor %}
  </ul>
{% endif %}

Unfortunately, I have a lot of nesting, and this is important for me. Thank you for the advice and the code provided.

Hello, I want to thank you again for a great plugin.
I was faced with the fact that you deleted it from the repository on GitHub. And I just had a question regarding the slug.
Is it possible to transliterate the Cyrillic alphabet for the slug generated by the plugin?
Exemle:
labels:Программы%20для%20Windows
to
labels:programmy-dlya-windows

I managed to redo your extension to achieve what I asked you to. Thank you again very much for creating it, it’s unfortunate that you deleted it from GitHub.

I have a similar need, but I have found that the plugin was deleted :disappointed:

@pamtbaau wonderful, very nice contribution to an open-source project, deleting the plugin …

Try me a redesigned version:

1 Like

Thanks a lot! @dydaevskiy

I will try it, for this small project I managed to separate categories in one list and tags in another, since they are not much. But I am sure I will love to use your plugin. Thanks for sharing it with the community :clap:. Your generosity is very much appreciated :pray:
Regards
joejac

1 Like

Old post but as this thread comes up first when I google how to get all taxonomy to display them :slight_smile:

A simple example to list all categories, for the categories (tags are separate but as explained in the thread, need two lookups for that):

{% set taxlist = taxonomy.taxonomy()['category'] %} 

{{ dump(taxonomy.taxonomy()) }}

{{ dump(taxlist) }}

{% if taxlist %} 

{% for tax,value in taxlist %} 

{{ dump(tax) }}</br>

{{ dump(value) }}

{% endfor %} 

{% endif %}

Other methods are available via twig, like findTaxonomy, if one likes to filter using given parameters (f.e. current page category)