New answers tagged

2

You need two different fields since you can only select one category group per category field. As you said, having two fields with the same name isn't possible. One way to work around this would be to add a behaviour that checks the entry type and returns the categories from the corresponding field (i.e. jobCategories for job entries and blogCategories for ...


2

If you don't want to build a custom plugin, this would be a good time to use Twig's reduce filter, which takes a set of values and iterates over them to output a single value based on supplied logic. Using Andy's answer as the basis might look like this (untested): {% set currentYear = now|date('Y') %} {% set loyaltyScore = currentUser.years.all()|reduce( ...


1

Pseudo-code: Fetch all category values, push the year string to an array. Sort that array in descending order by value. Initialise a counter, loop over the array, cast each value as an integer: -- if first array value is same as the current year, increase a counter, otherwise break. -- if loop year equals previous loop year minus 1, increase a counter ...


1

You could sort using the multisort filter (docs) then paginate using Yii's ArrayDataProvider - see this post for reference. {# Fetch your entries and order by theYear descending #} {% set allEntriesByYear = craft.entries() .section('library') .orderBy('postDate DESC') .theYear(':notempty:') .with(['theYear']) .all() | multisort(e => e....


0

For this kind of thing, I don't see much advantage of using a category relationship for the years (unless each category actually has further meta data or content held against it) - I'd probably just use a normal number field and get the editors to type in the year (or select from a pre-made dropdown if the range is reasonable)... But that doesn't help you ...


Top 50 recent answers are included