In a structure like the following:

Offices             US          Albuquerque
[offices]                       Boston

                    Mexico      Acapulco

                    Canada      Ajax

writing this code on the offices overview page

{% for entry in craft.entries.section('offices') %}

<h2>{{ entry.title }}</h2>

{% endfor %}

gives me an output of everything in the whole structure

when writing:

{% for entry in craft.entries.section('offices').level(1) %}

<h2>{{ entry.title }}</h2>

{% endfor %}

I get the title from the entry in the first level.

But how do i target a specific entry in the structure? Let's say only Albuquerque, Chicago & Chihuahua?

I looked around but can't seem to find anything in the docs about that. Who can point me in the right direction?


Based on your response to the answer from @Andre, you could make a "Featured" lightswitch field and use that in your query.

So, you would add a Lightswitch Field called "Featured" (handle: featured) or something of the sort. Then, from the entry itself you Toggle this on for the one you want to show up on the homepage.

The code would change to:

{% set featuredEntry = craft.entries.section('offices').featured(1).first %}
{{ featuredEntry.title }}

This has the tertiary benefit of the CMS controlling which office hours show up on the homepage should they need to be changed by the client. Just be wary if multiple lightswitches are turned "on". I believe it would take the first one in the sort order in that case.


Based on the comment below, you could solve this by creating a Drop Down field with days of the week as the Key => Value pairs, and then query your entries based on the day of the week it is:

Dropdown field with a handle of featuredDay with options:

| label  | value  |
| Sunday | sunday |
| Monday | monday |


Then in your template:

{% set featuredEntry = craft.entries.section('offices').featuredDay(now|date('l')|lower).first %}
{{ featuredEntry.title }}
  • thx for your input, great idea, but the openings hours will be visible for certain days in the week. Monday > Albuquerque, Tuesday > Boston, etc..
    – eek-a-edge
    Sep 30 '14 at 15:17
  • Sure. So, there's a number of ways you could handle this, but one way using the above method would be use a featured Drop down field instead. I've updated the answer with this use case.
    – Peter Tell
    Sep 30 '14 at 16:58
  • thx.. it did it like this {% for entry in craft.entries.section('offices').level(2) %} {% if entry.dayOfEvent == "now" | date("l") %} {# output #} {% endif %} {% endfor %}
    – eek-a-edge
    Sep 30 '14 at 18:17

To get a specific entry you need to know the id or slug of the entry. If the slug for Chicago is "chicago" (you find the slug in the side panel of the entry edit screen), you can get it like this:

{% set chicagoEntry = craft.entries.slug('chicago') %}

But hardcoding slugs and id's into templates is rarely a good idea. If you explain a bit more what you're trying to achieve, maybe we can provide a more helpful answer.

If you're trying to turn the structure into a menu of sorts, have a look at the documentation for the {% nav %} function, it was made specifically for this.

  • Thx.. Indeed i'm trying to avoid hardcoding as much as possible. I'm trying to understand how structures work and how i can target certain pages within my structure. I need to give a listing of all offices and also list the openingshours of a certain office on the home page.
    – eek-a-edge
    Sep 30 '14 at 11:01

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.