Forum

Thread tagged as: Question, Runway, Blog

Using Collections Within Perch Blog

Hi all,

I am trying to combine collections with perch blog so I can filter and display blog posts around the site.

So, one example is that I have set up staff profile pages in collections so I can then use staff profiles on other pages around the site, like on each department page to show the staff within that department.

However, on the staff profile pages themselves, I would like to have the latest 4 blog posts that the staff member has written. So in the blog post template /perch/templates/blog/post.html, I have added the following to be able to select and display the author of the post, which then links to their profile page...

<perch:related id="author" collection="Staff Profiles" label="Author" suppress="true" divider-before="Meta information">
    <perch:blog id="img1" type="image" width="400" height="400" crop="true" />
    <perch:blog id="name" type="text" />
    <perch:blog id="surname" type="text" />
    <perch:blog id="position" type="select" />
    <perch:blog id="profileSlug" type="slug" />
</perch:related>

...and then on the collection page template, /perch/templates/pages/about/staff_profile.php I have got the following to filter and display the blog posts from that member of staff...

    perch_blog_custom([
        'sort' => 'postDateTime',
        'sort-order' => DESC,
        'count' => 4,
        'template' => 'profile_posts.html',
        'filter' => 'profileSlug',
        'match' => 'eq',
        'value' => perch_get('profileSlug'),
    ]);

...but nothing is showing.

As per normal I'm sure it's something really simple, so any help or pointers would be much appreciated.

Glen

Glen Piggott

Glen Piggott 0 points

  • 2 weeks ago
Robert Ketter

Robert Ketter 95 points
Registered Developer

do you have a variable of "profileSlug" on the url? perch_get is looking for this on the url... or in runway routing if using runway.

Hello Glen,

You need to use 'filter' => 'author.profileSlug',

Hussein Al Hammad said:

Hello Glen,

You need to use 'filter' => 'author.profileSlug',

Perfect - thank you Hussein!