15

Brandon commented on getting tag usage count (and how it can be expensive) in this Google+ post and again in this SE question where I was trying to think through a plugin. So to completely steal from that, you could loop through your tags and get a count for each... {% set tags = craft.tags.find() %} {% for tag in tags %} {% set count = craft.entries....


12

Marion Newlevant had a clever, efficient idea in this Straight Up Craft Hangout if you don't mind having a slight lag (like a day) for your tag counts to be up to date. That idea: store the counts you need in a Preparse field on each tag, and set up a cron job to re-save all tags periodically. 1. Set Up Preparse Preparse is a free plugin from André Elvan ...


9

So P&T chipped in to help and of course solved my plight immediately :D For anyone else who might encounter a similar scenario I'm posting the solution. On the page containing the archive list: {% set allEntries = craft.entries.section('sectionName').limit(null) %} <ul id="archive"> {% for year, entriesInYear in allEntries | group("postDate....


9

{% set groupedEntries = entriesInYear | group("postDate|date('F')") %} Will give you an associative array where the keys are the months, and the values are the entries for that month. Now you need to loop over all the months, not just the ones in the groupedEntries. Make an array of all the months. {% set allTheMonths = ['January', 'February', 'March', .....


7

Figured out a way to do this if anyone who has the same problem. {% if year is defined and month is defined %} {% set archiveDate = year ~ '-' ~ month ~ '-01' %} <h2 class='archive-title'>Archive for {{ archiveDate|date('F') }} - {{ year }}</h2> {% endif %}


5

The value you need to set the postDate parameter to is quite complex. If you define a dedicated variable for it, it makes the code more readable and you can more easily debug the value using the dump() function. For the problem itself, you were on the right track. The main problem is a syntax mistake, you are passing in the 'and', '>= ', ... values ...


5

The better approach in my opinion is to declare the variables in the corresponding templates rather than in the _layout template Layout.twig {% if seoTitle is not defined or seoTitle is empty %} {% set seoTitle = config.seoTitle %} <-- fallback if nothing is defined {% endif %} <title>{{ siteName }} - {{ seoTitle }}</title> _entry.twig ...


5

I've used this method for sorting by year and month (it could be expanded to support days). On the news/index.html template: {% if month is defined %} {# show an archive of a month #} {% set sortDate = year ~ '-' ~ month %} Entry Date: {{ sortDate }} {% if month != 12 %} {% set nextmonth = month+1 %} {% set nextyear = year %} ...


3

There's probably a cleaner way to go about this, but something like this should work: {# These are probably coming from the querystring, but I'll hard code them here #} {% set year = 2015 %} {% set month = 'July' %} {% set entriesInYear = craft.entries.section('news').limit(null).after(year).before(year+1) %} {% set groupedEntries = entriesInYear | group("...


3

Here's what's happening... Every time you get "December", it's because the date is being parsed as December 31, 1969 (aka, just before the Unix Epoch). Basically, it's failing to parse the date properly, and thus defaulting back to the Epoch. And here's why... date(key) is basically saying "Get the date of 4". Which obviously doesn't make any sense. So the "...


2

You can't create a date from a single digit. This is what I would do instead: Get the localized names from Craft's data set with this function: {% set monthName = craft.i18n.getLocaleData().getMonthName(key)|date('F') %} There some info about that craft.i18n.getLocaleData in a Craft help article: "How do I access locale data from my templates?" Create a ...


2

Your postDate.day will output the number of the day in the month so if your entries postdate is 02.dd.yyyy your output is 2. Your array index will be something like [2, 3, 5, 12, 31] thus these values will be converted from the timestamp into a readable day with<h2>{{ day | date('Y-m-d') }}</h2>. The first timestamp (0) is 01.01.1970 because of ...


2

You'd need to use Twig's string concatenation in order to do this with the ~ operator. {% set entries = craft.entries.section('calendar').search('eventstart:' ~ year ~ '-' ~ month) %}


2

Try this: {% set entriesInYear = craft.entries .section('agenda') .limit(null) . dateAndTime([ 'and', '>=' ~ year, '<' ~ (year + 1) ]) .all() %} The .before() and .after() methods are convenience methods that hide the complexity of the date query on Craft's postDate field. They don't affect any other custom ...


2

Assuming the years are currently rendered in the correct (descending) order, an easy way to make sure the entries are rendered in ascending order would be to simply reverse the entriesInYear array, i.e.: ... {% for entry in entriesInYear|reverse %} ... {% endfor %}


1

This should be fixed for the upcoming 3.2.11 release. To get the fix early, change your craftcms/cms requirement in composer.json to: "require": { "craftcms/cms": "dev-develop#87fd6ca6b0c57f524c8ccae895c13eb9724d0efa as 3.2.10", "...": "..." } Then run composer update.


1

Try this: {% set year = craft.request.segment(4) %} {% set month = craft.request.segment(5) %} {% set entriesInYear = craft.entries.section('bulletinOnline').limit(null).after(year).before(year+1) %} {% set groupedEntries = entriesInYear | group("postDate|date('m')") %} {% for year, entriesInYear in allEntries | group("postDate.year") %} {% for month,...


1

It seems that before and after() don't work with the year as an int, if instead of '2018', you use '2018-01-01', your code works again. Check this. Basically, use a DateTime object :)


1

The code on the left is what you want to use... Here are the general steps to follow to put everything together. Since you're creating an archive page, you have to explicitly tell Craft what to do. First step then is to set the URL to something like: href="/chamber-news/archive/{{ month }}/{{ year }}" Then set up a template (my example uses one named "...


1

The way I do this is to use a different template for each set of entries. So there would be an archive one for all the articles from a given month: _news/index-archive, and a category one for all the articles in a given category: _news/index-category, and one for all of the entries: _news/index-all, maybe one for articles by tag, etc. Each of these ...


1

Sounds like you are missing a few tags, which we can fix when you post your code. Meanwhile, if you can spare the time, checkout Mijingo.com Craft Essentials, it's like being in the matrix as within one day you'll know lots about Craft! It will safe you lots of time figuring out the basics....


1

100% untested, but something like this should work using Twig's date_modify filter. {% set startDate = now|date_modify("-6 months") %} {% set allEntries = craft.entries.section('blog').limit(null).postDate('>= ' ~ startDate) %} {% for date, entries in allEntries | group("postDate|date('F Y')") %} <h2>{{ date }}</h2> <ul> ...


1

If you change your query and sort by ascending postdate, it will start with the oldest and end with the newest: {% set entriesInYear = craft.entries.section('blog').limit(null).after(year).before(year+1).order('postDate asc') %}


1

I ended up getting my archive list working using 'after' and 'before' parameters like below. {% if year is not defined %} {% redirect "news/archives/"~now.year %} {% endif %} {% set year = craft.request.segment(3) %} {% set month = craft.request.segment(4) %} {% set day = craft.request.segment(5) %} Year: {{ year }}<br> Month: {{ month }}<...


Only top voted, non community-wiki answers of a minimum length are eligible