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

Adding "Related Pages" Plugin to Antimatter Theme

Started by Tanzir Rahman 9 years ago · 14 replies · 1844 views
9 years ago

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.

9 years ago

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.

9 years ago

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

9 years ago

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

9 years ago

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:

YAML
filter:
  items:
    @page: /blog/home

Hope this helps

9 years ago

Already tried after @renards suggested, still not showing.

9 years ago

@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?

9 years ago

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

9 years ago

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

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).

9 years ago

@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.

9 years ago

@tanz1r:
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:

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):

TWIG
{% 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 🤷‍♂️

9 years ago

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

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 82 11 hours ago
General · by pamtbaau, 16 hours ago
1 53 16 hours ago
General · by Andy Miller, 1 day ago
0 45 1 day ago
General · by Marcel, 12 months ago
6 347 5 days ago
General · by Duc , 5 days ago
3 41 5 days ago