1

I've got a blog listing channel set up where I'm trying to filter entries listed by the entries field blogAuthors based on url segment.

/articles-and-excerpts/ loads the blog fine

added a route

enter image description here

but when I go to a page like this /articles-and-excperts/author/john-doe I see errors until I add this to the template

{% if entry is not defined %}
    {% set entry = craft.entries.section('blogListing').one() %}
{% endif %}

Then it works correctly. Why doesn't Craft recognize that this is the blogListing channel?

Also even though this works and displays the content SEOmatic doesn't recognize it now either.

Ultimately I need the following to load on this template:

/articles-and-excerpts/ /articles-and-excerpts/author/author.slug /articles-and-excerpts/category/category.slug /articles-and-excerpts/category/category.slug/author/author.slug

Currently I have categories using a separate template but haven't attempted to add in the author filtering.

Is there a better approach to this? I had started trying to combine url segments and a query string, but got stuck there as well Filtering entries by category and author channel

2

Variables like entry are only auto-injected for routes that match the Section's Site Settings routes:

enter image description here

If you're using custom routes, they won't match, and you'll need to set entry (or whatever) yourself manually. SEOmatic uses the same Craft mechanism for recognizing injected entrys (or whatever), so the same applies there. Vide: Rendering Metadata From Another Route

|improve this answer|||||
  • Andrew - perfect. Thank you. Of course I should've checked your blog before posting here. – CreateSean Nov 18 '19 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.