getgrav / grav-plugin-taxonomylist

Grav TaxonomyList Plugin
https://getgrav.org
MIT License
25 stars 14 forks source link

Limit tag list #24

Open metbril opened 6 years ago

metbril commented 6 years ago

I have a long list of tags, that is shown in the sidebar in full. Therefor I suggest the following features:

Limit number of tags

Add a config parameter limit:. Type is number. Default is 0. If limit is 0 all tags will be shown.

The parameter specifies how many tags will be included from the top of the list, assuming that the list is sorted descending by the number of times a tag is used. Basically the 'top x' items.

Threshold for count

Add a config parameter treshold:. Type is number. Default is 0. If treshold is 0 or 1, then all tags will be shown.

The parameter specifies how many times a tag should have been used before it appears in the list. If, for example, treshold is 3, then only tags that are used at least 3 times will be shown.

ghost commented 6 years ago

When I noticed you have the same problem I had, I thought I would got the chance to slightly contribute to this project and help the community. So here I am. I patched the plugin with some tiny changing of the yaml files and the template. I don't know if devs will accept my pull request, but it seems to work pretty fine. If you want, you can find my solution in pull requests.

metbril commented 6 years ago

Thanks. I will try this asap.

The PR #25 only implements half of my request, but it's a good start.

Still missing: the threshold.

metbril commented 6 years ago

There are actually 2 possible scenarios to achieve this:

  1. Build a limited list (in the build() method
  2. Limit the output in the .twig template

The latter is probably easier to achieve and makes is possible to use different limits (or none at all) in other places in the site.

My assumption is, that adding code to a twig template that can (if needed) be called with parameters limit and/or threshold will be the best implementation.

It would be nice if this is included in the plugin, but I guess this can also be done in a custom template.

metbril commented 6 years ago

This is what I'm using currently

{# Customized from taxonomylist plugin #}

{% set taxlist = children_only is defined ? taxonomylist.getChildPagesTags() : taxonomylist.get() %}

{% set limit = 20 %} {# show only the first x items #}
{% set treshold = 3 %} {# at least this number of times used #}

{% if taxlist %}
<span class="tags">
    {% set i = 0 %}
    {% for tax,value in taxlist[taxonomy] if (((limit is not defined) or (i < limit)) and (treshold is not defined or (value >= treshold))) %}
        {% set active = uri.param(taxonomy) == tax? 'active' : '' %}
        <a class="{{ active }}" href="{{ base_url }}/{{ taxonomy }}{{ config.system.param_sep }}{{ tax }}">{{ tax }} ({{ value }})</a>
        {% set i = i + 1 %}
    {% endfor %}
</span>
{% endif %}
simogeo commented 2 years ago

same issue here. For example here : https://www.intermezzo-coop.eu/fr/actualites/tag:Chandigarh

Only 5 news are listed but it should be more ! Any help most welcome. Thanks