Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.
38 votes
Accepted

How to return a specific entry?

This is the correct way. Examples: Singles: {% set entry = craft.entries.section('section_handle').one() %} Channels / Structures: {% set entry = craft.entries.section('section_handle').slug('my_slug'...
user avatar
  • 8,316
29 votes
Accepted

Is it possible to exclude multiple sections from an entry search query?

The trick is to add and once before the first not {% set entries = craft.entries.search(query).section('and, not this, not that') %}
user avatar
  • 3,664
25 votes
Accepted

Changed section from Channel to Structure, but can't re-order entries

Have you switched sorting to "Structure"? When you're not sorting by Structure, you won't be able to rearrange the entries.
user avatar
22 votes
Accepted

Get the current section handle

One thing that’s important to remember is that there’s no inherent relationship between your templates and sections. Any template can show any entry from any section. So there’s no such thing as the “...
user avatar
22 votes
Accepted

How to get one random entry from among multiple sections

According to the docs, you can pass an array into the "section" parameter: {% set entries = craft.entries.section(['quotes','didYouKnow']) %} There are several ways to get a random entry, but the ...
user avatar
  • 23.6k
15 votes

How can you get an entry type's name from its handle in a template?

A simpler way to do this might be: {{ entry.type.name }}
user avatar
15 votes
Accepted

Move entries between sections

It’s currently only possible via direct manipulation of the entries in your database. You will first need to visit your sections table to determine the desired section ID, and then the entrytypes ...
user avatar
13 votes
Accepted

How to create a CMS editable channel section index page?

Create a Single called "Blog Overview" and set its URI to "blog" and its "Entry Template" to "blog/index" (your blog listing template). Then just override the title to "Blog" either by hard coding it ...
user avatar
  • 2,975
13 votes

How does the Structure section type work?

I don't know if its possible to be much clearer than the official docs on this matter, but basically a Structure is needed if your entries needs to be in a specific order (and you want to manage that ...
user avatar
12 votes
Accepted

How do I return ALL entries that are singles

There's no such method available for craft.entries, at least it's not documented. But you can use craft.sections to get an array of section models and filter them with a conditional within a loop: {# ...
user avatar
  • 35.8k
12 votes
Accepted

Output children of a structure section in reverse order

The primary parameter you're looking for is lft: craft.entries.section('volumes').order('lft desc')
user avatar
  • 35.8k
11 votes
Accepted

Loading javascript on specific sections/pages

A safe way to add JavaScript resources via the frontend, is to use the {% includeJsFile %} Twig function in your template. The nice thing about the includeJsFile function is that it doesn't matter ...
user avatar
9 votes
Accepted

How to handle top-level/index pages in structure sections?

I recently setup a structure which contains (almost) every page of my site. When I set it up, I specified only {slug} as the URL. So far, it's working fantastically! And that's with about 30-40 pages ...
user avatar
  • 23.6k
9 votes
Accepted

How can you get an entry type's name from its handle in a template?

Classic find the answer straight after posting. The getEntryTypes method of the sections model allows you to choose how the array is indexed. This means you can do this: {% set entryTypes = section....
user avatar
8 votes

Output children of a structure section in reverse order

You could try using use the reverse twig filter. {% for entry in craft.entries.section('volumes')|reverse %} ... {% endfor %}
user avatar
7 votes

Set Default Entry Types for elements in a Structure Section

I'm not sure if you can set a default entry type within Craft. But a reasonably workaround would be to go to Settings > Sections, then click 'Edit entry types' for the section you need to apply this ...
user avatar
  • 3,594
7 votes

Can I extend entries listing views (currently or in the future)?

The current answer to this is no, not out of the box. The unofficial answer to this is, it has been discussed several times out there in the forums and there are some good arguments to make that this ...
user avatar
  • 13.2k
7 votes

How to use a Structure including a homepage

You can place your homepage entry in a Structure by setting its slug to __home__. Doing so causes the entry to answer for the / (empty) URI, and it even places the little "home" icon in place of the ...
user avatar
  • 3,390
7 votes
Accepted

Section Single Title Caching

For anyone stuck on this -- when changing a Section's name you have to goto the entry under Entries and hit save. This will update the mysql row / title.
user avatar
6 votes
Accepted

Use postDate in section title format field

The entry will be passed to this template as a variable named object. When you want to reference its properties you have two options: {postDate} (single braces) {{object.postDate}} (regular Twig ...
user avatar
6 votes
Accepted

Output URL to section

The url's are always bound to entries. And with your current code, you're getting all entries in the 'contact' section, not the section itself. But if this is a single, what you want is the url of ...
user avatar
  • 7,228
6 votes

Modelling flexible content sections and recommendations

I'm not familiar with ACF, but if you're looking for blocks-within-blocks, you could use the Neo plugin/fieldType. It allows you to define blocks, and then have nested blocks. It allows for decent ...
user avatar
6 votes
Accepted

Why would I choose Channels as opposed to Structures

From the official docs: Channels are used for streams of similar content Structures are good for times when you need to store multiple similar entries, and they need to be sorted into a specific ...
user avatar
6 votes
Accepted

Best way to find sectionId by slug

This should work: $section = craft()->sections->getSectionByHandle('sectionHandle'); $sectionId = section->id;
user avatar
  • 35.8k
6 votes

Most efficient way to check if a section has any active entries

You can use {{ craft.entries.section('whatever').total() }} for that.
user avatar
  • 2,947
5 votes
Accepted

Sections, Categories, and EntryTypes. Which, when?

Sections are for completely separate areas of content. They have their own URLs, and are conceptually different. Like blog posts and press releases would be different sections. Your sections could ...
user avatar
5 votes
Accepted

Updating all entries URIs after changing entry URL format

The entries won't immediately get updated, as it could take a little while to go through all of them, but you should see a little progress bar in your CP header immediately after updating your section'...
user avatar
5 votes
Accepted

How to create sub-nav when using a structured navigation heirarchy?

There is an nice recipe on the craftcookbook.net site from sprocketeer that explains exactly this. {% set topEntry = craft.entries.depth(1).slug('information').first() %} <ul> {% nav ...
user avatar
5 votes

Building a website containing restaurant menus from multiple vendors -- need some advice on Section hierarchy of data

Ok, just spitballing here, but this is where my brain is going... Channel: Restaurants Each restaurant is a unique entity, correct? So they wouldn't need to be in any specific order, nor nested. (...
user avatar
  • 23.6k
5 votes

Building a website containing restaurant menus from multiple vendors -- need some advice on Section hierarchy of data

As suggested by Lyndsey D, use the LJ Dynamic Fields plugin with the following Twig code to create your dynamic dropdown menu. It appears that Craft doesn't have a built-in way for an entry to self-...
user avatar

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