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


#24

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?


#25

@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.


#26

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:


#27

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

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

#28

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.


#29

@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…


#30

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:

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.


#31

@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:


#32

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