Hi!
There is a URL /articles
It is necessary to show only the articles of one author in this URL. How can I do it?
Now it works like this:
<ul>
{% for p in page.find('/articles').children %}
{% for a in p.taxonomy.author %}
{% if a == author %}
<li><a href="{{ p.url }}">{{ p.title|e }}</a></li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
But check {% if page.find('/articles').children %}
isn’t work correctly. Thanks.
{% set acnt = 0 %}
{% set pages = page.find('/articles').children %}
{% for p in pages %}
{% for a in p.taxonomy.author %}
{% if a == author %}
{% set acnt = acnt + 1 %}
{% endif %}
{% endfor %}
{% endfor %}
{% if acnt %}
<section class="uk-width-1-2@m articles">
<h2>{{ 'ARTICLES'|t }}</h2>
<ul class="uk-list uk-nav-default">
{% for p in pages %}
{% for a in p.taxonomy.author %}
{% if a == author %}
<li>
<a href="{{ p.url }}">{{ p.title|e }}</a>
</li>
{% endif %}
{% endfor %}
{% endfor %}
</ul>
</section>
{% endif %}
Now it work. It looks terrible. But work.
@rustark, It seems you want to have a collection of pages which are the children of a specific route, but only if author equals some name. Correct?
Have a look at the documentation on Page Collections.
You can define a collection in the header of the page, like:
content:
items:
'@page.children': '/articles'
or dynamically in Twig:
{% set collection = page.evaluate([{'@page.children':'/articles'}]) %}
To address your specific question, the following will create:
- a collection ‘coll1’ of all children below ‘/articles’
- a collection ‘coll2’ of all pages with taxonomy of specific author
- a collection ‘pages’ which is the intersection of the two yielding all pages below ‘/article’ which have the correct author.
{% set author = 'an author' %}
{% set coll1 = page.evaluate({'@page.children':'/articles'}) %}
{% set coll2 = page.evaluate({'@taxonomy': {'author': author}}) %}
{% set pages = coll1.intersect(coll2) %}
The pages contain the following header:
---
taxonomy:
author: 'an author'
---
1 Like
Thanks! It’s work.
{% set autor = 'Name' %}
{% set articles = page.evaluate({'@page.children':'/articles'}) %}
{% set authors = page.evaluate({'@taxonomy': {'author': author}}) %}
{% set pages = articles.intersect(authors) %}
{% if pages|length > 0 %}
<section>
<ul>
{% for p in pages %}
<li><a href="{{ p.url }}">{{ p.title|e }}</a></li>
{% endfor %}
</ul>
</section>
{% endif %}
1 Like