14
votes
Accepted
How to fetch entries from multiple sections
You can insert an array of different sections instead of a single one to pull entries from multiple sections
{% set entries = craft.entries.section(['sectionHandle', 'sectionHandleTwo']).limit(10) %}
...
9
votes
Nested Entries in Craft 3
I kind of found a work around, but doesn't seem like it's the correct way to be doing this.
{parent.uri ? parent.uri : 'static'}/{slug}
8
votes
Accepted
Entry Form - Multiple Entries & Entry Type & Parent
A little bit late but here it is.
Go to https://pluginfactory.io/ and create a plugin, you need at least 1 Controller but you can leave the Name value blank to create a controller with the same Name ...
7
votes
Best practice for channels and structures
You basically have two options for creating a "listing" or "archive" view for your Channel or Structure sections.
The first option is to create a Single. This is in many cases appropriate, e.g. if ...
6
votes
Accepted
URL structure for structure section
If you do this:
{parent.uri}/{slug}
You should get URLs like this:
site.com/parent
site.com/parent/child-1
site.com/parent/child-2
Does that make sense?
5
votes
Order/sort a structure section by date too?
This should work
{% set entries = craft.entries({
section: 'news',
sortOrder: 'postDate desc, lft asc',
}) %}
4
votes
Add home page to a structure?
From an IA and content-modelling perspective, putting all your site's "pages" in a Structure is fraught with problems, and, in my opinion, does a terrible disservice to the future-friendly approach ...
4
votes
Accepted
How to prevent select user groups from reordering structures
You should be able to ensure that the elements aren't moved by using the structures.onBeforeMoveElement hook in a plugin:
public function init()
{
craft()->on('structures.beforeMoveElement', ...
4
votes
Accepted
How to manage different templates for a structure
Your approach looks good to me. There are different ways you can make it happen:
If you set up your structure in the CP you can decide how many levels you want to allow for that structure. (By ...
4
votes
Accepted
How can I display second level children only from a specific parent structure item?
yes you can!
You may search for a slug craft.entries.slug('slug-of-first-parent'), select the first result .one(), and then the children by .getChildren(). Now you can proceed as you already did and ...
3
votes
Accepted
How do I check if a structure has any entries at level 3 when I'm at level 1?
To make it works I had to query in the section for descendant entries at level 3 of a current entry variable.
{% set products = craft.entries.section('products') %}
{% if lvl == 1 and products....
3
votes
Accepted
How to setup the structure in Craft for a Property Development site I'm building
I think I follow where you are going. It sounds like you have a few levels so you will indeed be working with a structure (instead of a channel or single).
I'm not sure what "All Developments" means -...
3
votes
Accepted
Hiding Field on Parent Entry
You can create two different Entry Types for your Structure section, and use one Entry Type for parent entries, and a different entry type for child entries. Entry Types have their own field layout, ...
3
votes
How to prevent select user groups from reordering structures
Impossible out of the box – there's no permission setting for ordering Structures. For now, I'd add a feature request and hack it in.
The easiest solution is probably to use the CP Body Classes and ...
3
votes
Accepted
Redirect to another EntryType template if no Children exist
Fixed!
So bearing in mind i'm using this method to load templates according to entry type, Clive Portman's answer got me thinking about hasDescendants. In my _entry.html I now have something like ...
3
votes
Accepted
Why isn't relatedTo not working (anymore)?
You are so close! All you need to do is to remove the ’.slug’, because that is what the param is expecting.
3
votes
Accepted
Start a Loop at the nth Entry in a Structure and Loop to the End?
Using the offset parameter you can achieve this:
{% for entry in craft.entries.section('structureSection').offset(8) %}
3
votes
Accepted
Eager-Loading child elements in a multi-level structure section
To use eager-loading for the child elements add 'children' to the with parameter.
{% set mice = craft.entries({
section: 'experiments',
level: 3,
descendantOf: entry.id,
with: ['...
3
votes
How can I create a family tree hierarchy in Craft?
I can't think of an easy and clean way to visualize this kind of structure in a default list. So if you want to be able to display the structure from your diagram dynamically you'll have much work to ...
3
votes
Accepted
Why is the parent slug showing up in the child slug in a structure?
Pretty sure that the ResaveElements task just hadn't run yet - my queue was stuck. Once I cleared the stuck items, the issue resolved on its own!
3
votes
URL Structure - advise and thoughts of best approach?
I’d go for /hot-tubs/used etc
This way you can also have /accessories/pipes etc
3
votes
URL Structure - advise and thoughts of best approach?
The general rule of thumb is to start with the most general thing, and end in the most specific thing. The nice part of this is that it makes sense to humans, too.
I'd go with /hot-tubs/new/name-of-...
3
votes
Accepted
How do I get different URL Format with parent/child structures & how do I display different templates?
To get different URL Format for parent & child pages, you need to go to the CP structure settings and edit the Entry URI Format. This is how your URI should look like:
{% if level == 1 %}features/...
3
votes
Accepted
How do I create a structure side navigation that will show active parent list-item and active child list-item
After a long search and lots of trial and error, I've found the perfect solution!
This is how I created a dynamic structure navigation : parent/child (2 levels deep) with class="active" on the parent ...
3
votes
Accepted
Craft CMS Structure: How can I display parent and child items on an active parent page?
I hope I have understand your problem..
Let's look at your code:
One sidenote: It might be good to limit your pages-selection only to active pages:
{% set pages = craft.entries.section('about')....
3
votes
Accepted
Parent are not set anymore after saveElement()
You need to use newParentId:
$navigationItem = new Entry();
$navigationItem->typeId = 4;
$navigationItem->sectionId = $navigationSection->id;
$navigationItem->title = $entry->title;
$...
3
votes
Accepted
Simple Product Listing Pages by Category Slug
You're nearly there! You are missing the part that fetches the entries related to your category.
With your current set up, you would need to do:
{# Get the requested category slug from the URL #}
{% ...
3
votes
Accepted
Get all entries by structureId
Looks like you're trying to access an entries' descendants, which includes all children, children of children and so on. You can get all descendants of an entry using Entry::getDescendants():
{% set ...
3
votes
Convert Categories into Structure entries
Craft 4.4 (which is due to release in Q1 2023) will include a native CLI command that will "aid in migrating existing categories, tags, and global sets over to entries". Full details here: ...
3
votes
Accepted
Disable Drag and Drop movements of entries
None of these are currently possible, as far as I know.
A quick search reveals this abandoned plugin, this feature request and, lo and behold, a feature request created by you in 2022.
I’d say that ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
structure × 273entries × 58
navigation × 33
sections × 27
templating × 22
categories × 21
children × 20
channels × 15
entry × 14
url × 14
craft3 × 13
relations × 13
parents × 13
entry-type × 9
matrix × 8
content × 7
singles × 7
routing × 6
best-practice × 6
category × 5
entries-field × 5
ordering × 5
plugin-development × 4
control-panel × 4
field × 4