Adding "Related Pages" Plugin to Antimatter Theme

Did an auto-installation of the related pages plugin.

All my blog posts are saved with the “Default” template.

So, I added this within block content:

{% if config.plugins.relatedpages.enabled and related_pages|length > 0 %}
Related Posts
{% include ‘partials/relatedpages.html.twig’ %}
{% endif %}

To my default.html.twig

But, it’s not showing.

My website: thirdhandbd.com/blog

Plugin: https://github.com/getgrav/grav-plugin-relatedpages

Please help. Let me know if you have questions.

Maybe it’s related to this:
https://github.com/getgrav/grav-plugin-relatedpages/issues/17

If you edit the relatedpages.yaml file through your editor, it should work.

Thanks for the reply, Paul. I was really excited to give this a try, but sadly it hasn’t worked for me. I tried numerous combinations and cleared cache.

can you post the content of your relatedpages.yaml file?

enabled: true
limit: 5
show_score: true
score_threshold: 20
filter:
  items:
    '@page': /blog
  order:
    by: date
    dir: desc
page_in_filter: true
explicit_pages:
  process: true
  score: 100
taxonomy_match:
  taxonomy: tag
  taxonomy_taxonomy:
    process: true
    score_scale:
      1: '50'
      2: '75'
      3: '100'
  taxonomy_content:
    process: true
    score_scale:
      1: '20'
      2: '30'
      3: '45'
      4: '60'
      5: '70'
      6: '80'
      7: '90'
      8: '100'
content_match:
  process: false

Hi @tanz1r,

just an idea : did you try to change the path in your relatedpages.yaml file to /blog/home. I saw that your blog posts seem to be stored under this directory.
Example : https://thirdhandbd.com/blog/home/science-graphic-design-part-four

That was a good idea. Just tried it, no luck… :frowning:

I just had the same issue getting this plugin to work. Setting Items via the Admin UI produces invalid yaml as @paul pointed out and linked to the issue.

@tanz1r you need to edit the yaml file via text editor/shell and set it as such since you’re using a custom route, like:

filter:
  items:
    @page: /blog/home

Hope this helps

Already tried after @renards suggested, still not showing.

@tanz1r Can you enable the debugger, clear cache, and tell us if you see a message?
Also, can you try by adding some explicit_pages on some of them?

@paul, I did clear cache. How do I enable debugger and add explcit_pages? Sorry for the newbie question.

I’m curious why you are not using the “Item” template - I’ve been unable to get this plugin to work on default.html.twig for the “Default” template.

I did manage to get it to function on blog_item.html.twig and also sidebar.html.twig (where it is enabled by default).

@andy, what you suggested makes sense. I simply restored to Default because it was there and never bothered changing it, in fear of messing things up. I simply installed Grav, got somewhat familiar and started using it. I’m learning as these issues arise.

I changed all my blog posts to Item and it makes a lot more sense now, but Grav did something weird where it updated the publish dates of some of my posts.

Anyway, then I tried again to use related pages. I put it in both my sidebar and blog_item. Sadly, no luck. Related pages was not in the sidebar by default for me. I then went on and installed Random Article plugin and it’s working just fine. It was there in my sidebar by default. Also, random article didn’t work right away, I had to change the AND operator to OR.

The point in saying all of this is that, I am definitely missing something but I don’t know what. If you outline exact steps, directories that worked for you, it’d be more helpful for me. Maybe even your exact settings and configurations for your Grav.

Really appreciate the help. Hopefully these problems won’t arise as I get more familiar with Grav. I have been reading Grav documentation from the very start, it’s just new territory.

Definitely. I’ll see if I can provide some insight. First, here’s an example of a page with Related Pages in action from my site, which I recently redesigned to add the sidebar.

  • I’m using the Blog Site skeleton with a custom theme on top of Antimatter.

  • My route is not ‘blog’ but instead ‘home’, and it is hidden as you can see from the link above. As mentioned in a previous post the route must be changed manually in user/config/plugins/relatedpages.yaml. Here’s my full relatedpages.yaml:

enabled: true
limit: 7
show_score: true
score_threshold: 20
filter:
  items:
    @page: /home
  order:
    by: date
    dir: desc
page_in_filter: true
explicit_pages:
  process: true
  score: 100
taxonomy_match:
  taxonomy: tag
  taxonomy_taxonomy:
    process: true
    score_scale:
      1: '50'
      2: '75'
      3: '100'
  taxonomy_content:
    process: true
    score_scale:
      1: '20'
      2: '30'
      3: '45'
      4: '60'
      5: '70'
      6: '80'
      7: '90'
      8: '100'
content_match:
  process: false

user/themes/<theme-name>/templates/partials/sidebar.html.twig should contain this somewhere (for me I moved it up in the file to line 3):

{% if config.plugins.relatedpages.enabled and related_pages|length > 0 %}
    <h4>{{ 'SIDEBAR.RELATED_POSTS.HEADLINE'|t }}</h4>
    {% include 'partials/relatedpages.html.twig' %}
{% endif %}

However it sounds like you’ve done this already and it’s still not working :man_shrugging:

I’m feeling elated right now, to put it mildly!

My YAML edit should’ve been @page: /home as well just like yours, not /blog/home. It finally worked! Tears of joy.

2 Likes