I would like to have some advise on the following:

I'll be running a site with events. These events (channel entries) will take place in a certain city. I don't want to setup every city as a category, but use tags instead. My questions are:

  1. Is it logical to use tags for cities?
  2. Can I list all events based on a city (tag) on my template?



Probably and yes.

Using tags for cities:

If you want to allow users to add any city they want, tags are perfect. If not, you should predefine them, and use categories, dropdowns or multi-selects.

Since you don't know if the user has actually entered a city, you should consider validating it with a custom plugin:


List entries which have a specific tag:

You can use relations to find all entries which have a specific tag:

{% set tag = craft.tags.name('miami') %}
{% set relatedEntries = craft.entries.section('events').relatedTo(tag) %}

{# Gets all entries which have the 'miami' tag #}

I agree with Victor, but if you're looking to loop through all the cities (regardless of how many you have) and show entries related to them I'd do it like this:

{% set entries = craft.entries.section('events').limit(null) %}
{% for tag in craft.tags('cities') %}
    <h2>{{ tag }}</h2>
        {% for entry in entries.relatedTo(tag) %}
            {# entry #}
        {% endfor %}
{% endfor %}

There is an address plugin available, that might be useful for your event locations. It's called craft-smartmap by Lindsey D.

Addresses are auto-completed on input, latitude and longitude are calculated (for maps output etc.) and you have access to the cities names like with any other field type.

I don't know if it's overkill for your goals and you just need the city names. Nevertheless added this here as it might be worth a look.

  • Seconded. Incredible plugin and I believe he has some great features coming down the pipeline for it very soon :) Jul 3 '14 at 1:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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