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'...
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') %}
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.
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 “...
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 ...
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 }}
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 ...
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 ...
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 ...
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:
{# ...
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')
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 ...
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 ...
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....
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 %}
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 ...
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 ...
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 ...
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.
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 ...
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 ...
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 ...
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 ...
6
votes
Accepted
Best way to find sectionId by slug
This should work:
$section = craft()->sections->getSectionByHandle('sectionHandle');
$sectionId = section->id;
6
votes
Most efficient way to check if a section has any active entries
You can use {{ craft.entries.section('whatever').total() }} for that.
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 ...
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'...
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 ...
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. (...
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-...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
sections × 174entries × 35
structure × 27
templating × 26
url × 17
entry-type × 11
craft3 × 10
channels × 10
categories × 9
entry × 9
navigation × 8
localization × 7
plugin-development × 6
search × 6
singles × 6
matrix × 5
ordering × 5
best-practice × 5
assets × 4
users × 4
routes × 4
permissions × 4
slug × 4
relations × 3
field × 3