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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Plugins

Taxonomylist Plugin: problem with tags displaying empty pages

plugins

Started by chraebsli 2 years ago · 2 replies · 100 views
2 years ago

Hello everyone

Setup

On my Grav site, I have a main blog page with articles and subblogs with articles, a structure like this:

TXT
/blog
  /article-1
  /article-2
  /subblog-1
    /article-3
  /subblog-2
    /article-4

Each article has one or more tags, and every article of a subblog has at least the same tag as the subblog. Now I'm facing the problem that the taxonomylist plugin displays emtpy tags.

Problem

On my main blog page /blog, all tags get displayed, with articles, subblogs and those articles. No difficulties here so far. But then on a subblog page like /subblog-1, it not only displays tags of the articles, but also all other used tags, which aren't used on the subblog.
Because of that, I get a page looking like this:

screenshot of empty tag listing|690x316
As a reference, 'Tutorials' is the main blog page and 'Seiten' is the subblog, the page visited. Since there are no articles in this subblog with the tag 'Login', it displays an empty page. The URL/ Path is /tutorial/seiten/tag:Login, which means that it gets only the articles of the tag 'Logins' in the subblog 'Seiten'

possible Solutions

Two possible solutions come into my mind, but I don't know how to do it or where the problem is that it doesn't work:

  • S1 (Preferred): The plugin only displays the tags used within this subblog. So it is like a combined filtering, since it filters only articles below this subblog in general, and optionally a tag within this subblog.
  • S2: On the subblog, all tags of the entire blog page (main blog) get displayed. But when selecting a tag, it displays all articles, not only the ones from the subblog.

What I've tried

According to the README of the plugin, I tried including the taxonomylist with this, where I also tested it out with/ without the of_page and children_only separately and combined:

TWIG
{% include 'partials/taxonomylist.html.twig' with {
    'base_url':new_base_url, 
    'taxonomy':'tag', 
    children_only: true, 
    of_page: page.parent
} %}

I also tried setting of_page as a string, with the collection syntax (@), changed it to page.descendants so it gets only pages below, and some more ideas I had, but none of them solved the issue.

This is the partials/taxonomylist.html.twig file from the theme:

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

{% if taxlist %}
<span class="tags">
    {% for tax,value in taxlist[taxonomy] %}
        {% set label_class = uri.param(taxonomy) == tax ? 'label-primary' : 'label-secondary' %}
        <a class="label label-rounded {{ label_class }}" href="{{ base_url }}/{{ taxonomy }}{{ config.system.param_sep }}{{ tax }}">{{ tax }}</a>
    {% endfor %}
</span>
{% endif %}
2 years ago

Ok I really feel stupid for this, but it happened that I edited the template with the include from a theme I inherited and overridden. I figured this out when I was working on another enhancement which required the same template to be edited, but it had missing parts I made on my theme.

Sorry again, shit sometimes happens, and often it's the programmers' fault, not the programs'.

Have a nice week everyone!

2 years ago

Still having a problem with the main blog page.

On subblogs, it now displays only the tags within this blog. But on the main blog page /blog, it can't access the tags from articles of a subblog.

I'm still not very good with PHP, but my theory is that this is because of the getChildPagesTags function in the plugins /classes/taxonomylist.php, which only gets the children of a page and not all descendants. That would mean that it can get the tags of its articles and the subblogs, but not the articles of a subblog.

Am I right with assuming that there is no way for the plugin to access these tags too? Except for forking the plugin and do a little rewrite of the function?

Suggested topics

Topic Participants Replies Views Activity
Plugins · by Rene, 1 week ago
2 42 1 week ago
Plugins · by Xavier, 4 weeks ago
2 53 4 weeks ago
Plugins · by Luka Prinčič, 7 years ago
3 1179 1 month ago
Plugins · by Sebastian van de Meer, 1 month ago
1 47 1 month ago
Plugins · by PIERROT Alain, 2 months ago
3 71 2 months ago