I have an entry type whose content will be separated from the main content. So I was wondering how can we give an entry type its own search and categories? Possible?
1 Answer
Sure it's possible. There's the type()
parameter available for ElementCriteriaModels to filter the returned results by only those entry types you need.
To separate the categories, I'd set up multiple category groups, one for each of your entry types.
For example:
{% set categoryParams = {
group: 'audioCategories',
slug: 'podcasts'
} %}
{% set category = craft.categories(categoryParams).first() %}
{% set searchTerm = 'basketball OR soccer' %}
{% set entryParams = {
section: 'news',
type: 'audio',
relatedTo: category,
search: searchTerm
} %}
{% for entry in craft.entries(entryParams) %}
<li>{{ entry.title }}</li>
{% endfor %}
This would list only those entries which are
- in a section named "news"
- given an entry type (and entry template) "audio"
- related to a category from the category group "audioCategories" (I additionally filter for just the one cat. named "podcasts" to keep the example a little simpler)
- matching to the search term "basketball OR soccer"