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.

General

Filtered author taxonomy does not work if it is defined in the page header

Started by Pedro M 3 years ago · 3 replies · 315 views
3 years ago

Hello

What is the difference between having the author taxonomy defined in site.yaml and page.header.author? If I use the author taxonomy from site.yaml, I can filter blog pages by author, however, if I use the taxonomy in the page header, that filter doesn't work.

The following code

TWIG
{% if page.taxonomy.author %}
{% for author in page.taxonomy.author %}
       <a href="{{ base_url }}/author{{ config.system.param_sep }}{{ author }}">{{ author }}
{% end for %}
{% endif %}

Filter correctly by taxonomy if site.yaml is like this:

YAML
taxonomies:
   - category
   - tag
   - author

DO NOT filter by taxonomy if item.md is like this:

YAML
taxonomy:
     category:
         -category1
     tag:
         -tag1
     author:
         - Peter

I have defined the taxonomy according to this post:

Set Category and Tag (Taxonomies) as required

How can I solve this problem?

3 years ago

@pmoreno

In site.yaml you just define the types of taxonomies you like to use. And in item.md you define the taxonomy value for exactly that page.

E.g. I have in a similar use case:

Add desired taxonomies to site.yaml

YAML
taxonomies:
  - author
  - category
  - tag

Use it in blog_item.html.twig

TWIG
  {% if page.header.author %}
    {% set author = page.header.author %}
  {% else %}
    {% set author = array(page.header.taxonomy.author)[0] %}
  {% endif %}

which uses the data from

item.md frontmatter

YAML
taxonomy:
    author: abc
    category: blog
    tag: [2020, anyname]

Does that answer your question?

3 years ago

The saying goes that a picture is worth a thousand words.

I have modified some pages in the Future2021 theme demo to be able to show this error.

We have two pages, with the author "Ana", one with the author defined in the header of the page, Post Five,

post_five|410x500

page_header_post_five|553x469, 75%

and another with the author defined in the author taxonomy (previously defined in site.yaml), Grav Install.

grav_install|416x500, 100%

taxonomy_grav_install|435x500, 75%

Now, if we visit the blog, filtering the author "Ana", we get only one post, the post that has the author defined in the taxonomy (Grav Install) and NOT in the page header (Post Five)

http://future.juanvillen.es/blog/author:Ana

post_from_author|489x499, 75%

The question is the following: How can I get all the posts of an author, regardless of whether it is defined in taxonomies or in page header?

Sorry I can't express it better. Thanks in advance

3 years ago

OK, now I understand your issue. As far as I know .../author:Ana only works when the author is defined as taxonomy, but not when it's simply in the header.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 74 6 hours ago
General · by pamtbaau, 11 hours ago
1 47 11 hours ago
General · by Andy Miller, 23 hours ago
0 43 23 hours ago
General · by Marcel, 12 months ago
6 346 5 days ago
General · by Duc , 5 days ago
3 39 5 days ago