2

I'm trying to get an archive to work on a web page, based on entries per year. This, in combination with an isotope-like filtering of categories. I want to output entries based on year, and then output the categories attached to these posts to use for the filtering. I've managed to get the year sorting to work by using Low Yearly Archives, but I can't add a year parameter in the categories tag.

The code that outputs the categories looks like this:

{exp:channel:categories style="linear" channel="News" category_group="1" dynamic="no" show_empty="no"}
    <li><a class="filter" data-filter="{category_name}">{category_name}</a></li>
{/exp:channel:categories}

And the code that outputs the entries looks like this:

{exp:channel:entries channel="News" dynamic="no" limit="12" year="{segment_2}"}
  {title}
{/exp:channel:entries}

This takes the segment_2 from the url which low yearly archives outputs.

Now, the categories outputs all categories from all years, not the one from segment_2. If only the channel category tag had accepted a year parameter, this would have been solved. Any idea how to solve this? I've tried combining channel category and channel entries tags, but I can't get the combination to work.

Edit: I've tried the following:

{exp:channel:entries channel="News" dynamic="no" limit="12" year="{segment_2}"}
    <li><a class="filter" data-filter="{categories}{category_name}">{category_name}{/categories}</a></li>
{/exp:channel:entries}

And although this outputs the categories assigned to the corresponding posts, I get duplicates. So I need to output unique ones.

1 Answer 1

2

Tested this template on EE 2.7.2, and it appears to work.

We're going to use the channel entries loop you've already got to generate a list of entry id's, which we're going to feed to the remarkably handy GWcode Categories add-on, which will display a list of all of the categories that belong to the entries in question without duplicates.

{exp:gwcode_categories parse="inward" entry_id='{exp:channel:entries channel="news" dynamic="no" limit="12" ear="{segment_2}"}{entry_id}|{/exp:channel:entries}0'}
  {cat_name}
{/exp:gwcode_categories}

{cat_name} is all I'm outputting there, but, that add-on has a plethora of variables available; I'm sure you'll be able to display whatever you need.

A few other notes...

Not sure what the limit="12" is about; it should probably be removed, otherwise you're only going to be getting the categories for the first 12 entries each year.

disable="categories,custom_fields,member_data,pagination" should also probably be added to your exp:channel:entries to keep things as speedy as possible.

There's an extra "0" immediately following the channel entries loop; that's intentional, and is there to prevent issues with "no results" cases, and, prevents us from having to trim the trailing pipe - win-win, I say.

1
  • 1
    Thank you! I'll check this out :) I've managed to make it work by outputting each category into a php array. And then making that array unique, and then outputting those arrays into the markup. But this looks a lot cleaner :) The limit="12" is there because I only want to ouput 12 entries, the rest is available through pagination :) Jan 7, 2014 at 7:54

Your Answer

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

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