Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Displaying Related Pages by Tag instead of Category #7

Open
xhs345 opened this issue Sep 12, 2016 · 0 comments
Open

Displaying Related Pages by Tag instead of Category #7

xhs345 opened this issue Sep 12, 2016 · 0 comments

Comments

@xhs345
Copy link
Contributor

xhs345 commented Sep 12, 2016

Hi, it took me a while to realize that for SimpleSearch and Archives to work properly the default category for each blog post has to be "blog".
Now the reason I'm writing this issue is, that the related pages are displayed by category instead of tag by default in this theme. The RelatedPages Plugin uses Tag for relations by default as well.

This is the code I'm using now:

  {% if related.taxonomy.tag %}
  <p class="jp-relatedposts-post-context">
    {% set related_tags = array_intersect(related.taxonomy.tag, page.taxonomy.tag) %}
    {% if related_tags %}
    Shares Tag  
    {% for tag in related_tags %}
      {% if tag %}
      "{{ tag|capitalize }}" {% if not loop.last %}, {% endif %}
      {% endif %}
    {% endfor %}
    {% endif %}
  </p>
  {% endif %}

See https://github.com/getgrav/grav-theme-gateway/blob/develop/templates/partials/relatedpages.html.twig#L16 for comparison

Edit: Updated code so it only shows tags that are shared between blog post and related post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant