6

I'm creating a tumblr-esque blog with a bunch of different entry types.

One of the entry types will be named "Image". When I'm on the entry page for an "Image" entry, I'd like to be able to show 10 more entries with the same "Image" entry type.

Is this possible?

2 Answers 2

5

You can get the entry’s current type handle via entry.type, and craft.entries supports a type param for finding entries of a given type, so you can plug those two together:

{% set otherEntries = craft.entries.section('blog').type(entry.type) %}
5

Yes. This is certainly possible.

I'm not sure how you're templating / naming is setup but you can get entries by entry type and you can check an entry's type. To get entries by a specific type:

craft.entries.section('blog').find({type: 'imagePost', limit: 10})

Here's some helpful references for craft.entries: Entries Cheat Sheet - Craft Docs For the Entry Model

You could structure some kind of comparison, to see if the current entry is a specific type, and if it is query and render the desired additional entries.

{% if entry.type == 'imagePost' %}
  {% for post in craft.entries.section('blog').find({type: 'imagePost'}) %}
...
{% if entry.type == 'textPost' %}
  {% for post in craft.entries.section('blog').find({type: 'textPost'}) %}
...

However there are many ways to do what you want depending on your setup. Please note I used the name imagePost instead of image, to avoid any confusion there might be with a common name like image. I'm not sure if that could cause name conflicts or if it's a reserved keyword / field etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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