getgrav / grav-theme-gateway

Gateway incorporates elegant style with user friendly customizer options making it perfectly suited for a variety of Grav users. With rock solid development and flexible integration, the Gateway theme is sure to be a favorite for first time Grav users and experienced developers alike.
https://getgrav.org
GNU General Public License v2.0
12 stars 9 forks source link

Displaying Related Pages by Tag instead of Category #7

Open xhs345 opened 7 years ago

xhs345 commented 7 years ago

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