0

I have a channel called "offices" with a limited number of entries. Every entry is assigned to a different category from a Category Group called "office-categories". For instance the first entry is assigned to a category called "office-1".
I have another channel called "files" with unlimited entries assigned to categories from the same Category Group "office-categories".
In time a lot of entries will be assigned to the same category "office-1".
I cannot use the Relationship in the first channel because there are so many entries in the second channel that make difficult to find the ones that belong to a specific category.
In the single-entry page of the first channel I like to have the details of the first channel entry and all the entries (all the files) from the second channel that belongs to the same category "office-1". Can someone tell me if this can be done in EE and how? Thanks a lot

1 Answer 1

0

It might be that I have misunderstood your question, if so please clarify and I will try and improve the answer.

EE is well suited to doing just what (I think) you are trying to do - through its template system you can construct pages that have highly specific and unusual combinations of entries drawn from multiple channels.

Here are two ways you could achieve this outcome - there are many more I am sure.

1) you can take advantage of EE's option to nominate multiple channels in a channel entries call. So specify your category, the two channels, and your results will be all the entries across both channels that have that category. You can sort the output by channel_short_name - so get your first channel entry out first (or last); you can also test each result to see which of the two channels it came from to adjust your layout / markup accordingly.

{exp:channel:entries channel="channel_1|channel_2" category="office-1" orderby="channel_short_name"}
{if count == "1"}
... do stuff on the first channel entry ...
{if:else}
... do stuff on the remaining entries
{/if}
{/exp:channel:entries}

2) simply call each channel separately within the same template - you can do this as often as you like within a template (there is an overhead in processing time for each call you make, so keep it down to a few if you can)

{exp:channel:entries channel="channel_1" category="office-1"}   
... do stuff on the first channel entry ...   
{/exp:channel:entries}

{exp:channel:entries channel="channel_2" category="office-1"}   
... do stuff on the remaining entries   
{/exp:channel:entries}

HTH

10
  • The second example will do the job but I don't know how to do this dynamically. First will be a template with a list of all the entries from the first channel (offices), each one going to the detail page where I want to show all the details of that entry and all the entries in the second channel that correspond to the same category with that entry. Thanks for reply
    – Martin
    Commented Jul 19, 2019 at 14:22
  • The only thing that changes is the category it seems, so you simply need to adjust the category in each of the channel entries calls as you need it. There are many ways of doing this, but an easy one would be to use a slug in your url - for example have the URL like this: site.com/lists/office-1 and then change the channel entries calls to look like this: {exp:channel:entries channel="channel_1" category="{segment_2}" dynamic="no"} - the final parameter is important as it tells EE that you are telling it where to look and it should not try and guess based on URL. HTH Commented Jul 20, 2019 at 8:46
  • What I have now: One template where I list the entries from the first channel with link to a detailed page {exp:channel:categories channel="channel_1" style="linear" show_empty="no"} {exp:channel:entries channel="channel_1" category="{category_id}" dynamic="no"} <a href="{path=template_group/detail_page}/{entry_id}">{title}</a> {/exp:channel:entries} {/exp:channel:categories}
    – Martin
    Commented Jul 20, 2019 at 10:04
  • Then I have the template whit single-entry (detail_page) {exp:channel:entries channel="channel_1|channel_2" category="office-1" orderby="channel_short_name"} {if count == "1"} the staff from the first channel entry {if:else} list with all entries from the second channel {/if} {/exp:channel:entries} The link from the first page will open the second page but nothing shows up. If I open the second page directly, it will render correctly. The code in the first page is wrong and don't know how to fix it.
    – Martin
    Commented Jul 20, 2019 at 10:04
  • The URL you are passing from template 1 appears to be domain.com/template_group/detail_page/XX where XX is the entry ID of a channel 1 entry - i.e. {segment_3} = entry_id. But the second template does not use segment_3 to locate a specific channel 1 entry, so this extra segement is not going to do anything. Try changing the channel:entries parameters for second template to exp:channel:entries channel="channel_1" category="{category_id}" dynamic="no" entry_id='{segment_3}'. Also, where / how do you pass the category_id needed for 2nd template URL... ? Commented Jul 21, 2019 at 10:47

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.