18
votes
Accepted
How do I add a subcategory to the URL slug for a channel entry?
If you go into your Category Group’s settings and set the following settings:
Craft 2
Top Level URL Format: {slug}
Nested URL Format: {parent.uri}/{slug}
Craft 3
Category URI Format: {parent.uri}/{...
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 }}
14
votes
Accepted
How do I loop through entries for a specific entry type?
{% set entries = craft.entries.section('pages').type('blogPost') %}
{% for entry in entries %}
{{ entry.title }}
{% endfor %}
Is what I have cobbled together... any pointers on improvements would ...
14
votes
Accepted
Link to an entry via Entries field type
Even if you set the limit to 1, Craft always returns an array of entries. So you need to add first() to access the first (and only) entry.
{{ entry.buttonTargets.first() }}
It you don't add a ...
11
votes
Accepted
How do I display entries from multiple entry types?
You can set the ElementCriteriaModel's type parameter to multiple values by passing it an array of entry type slugs:
{% set teachers = craft.entries.section('teacher').type(['teacher', 'demoTeacher'])...
11
votes
10
votes
Accepted
Entry Types Custom Slug
You could just set your "Entry URL Format" to:
my-section/{type.name}/{slug}
Your entry type names couldn't be as clean when composing entries in the CP as you'd need to set them to something like "...
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
How to list the latest 5 entries per entry type?
craft.entries() fetches entries.
To fetch the entries with a given entry type, you use type. So to get the Article entries, either craft.entries.type('Article') or craft.entries({type: 'Article'})
...
8
votes
Accepted
Using an IF-statement to define the Entry URL Format
Alright, I was able to figure it out myself:
channel{% if object.type == 'xyz' %}/{type}{% endif %}/{slug}
produces the desired results. The section for Dynamic Entry Titles in the docs pointed me ...
8
votes
Accepted
{% if loop.first %} and {{ loop.index0 }} not working with Matrix
At the moment loop.first and loop.index0 are relative to your block.image loop.
If you want them to be set based on your entry.locationSlideshow loop (the parent loop) you can use {{ loop.parent.loop....
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
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
Accepted
Get next entry based on entry type
No, you still have to set the parameters by your own:
{# Get this entry's entry type #}
{% set type = entry.getType() %}
{# Set parameters for prev/next elements list #}
{% set params = craft....
7
votes
Accepted
How can I programmatically add a tab to entry type?
I eventually figured this out. Here's the code that's working for me:
$newFields = array(
0 => '12', // $field->fieldId
1 => '15' // $field->fieldId
);
// First we get all sections ...
5
votes
Accepted
Is it possible to show more entries of the same entry type as the current entry?
You can get the entry’s current type handle via entry.type, and craft.entries supports a type param for finding entries of a given type, so you can plug those two together:
{% set otherEntries = ...
5
votes
Is it possible to show more entries of the same entry type as the current entry?
Yes. This is certainly possible.
I'm not sure how you're templating / naming is setup but you can get entries by entry type and you can check an entry's type. To get entries by a specific type:
...
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
New route for entry types
You can have entry type specific templates for your entry pages, see this docs article on how you can do this. And for your archive pages, just set a route for each of them and point it to the ...
5
votes
Accepted
Different templates for different entry types within a section
Sounds like you're looking for something like this: https://craftcms.com/support/entry-type-templates
5
votes
Different templates for different entry types within a section
It is not possible to have dynamic tags within Entry Template settings, no. All fields that do allow dynamic tags will say so in their instruction text.
The reason it’s allowed in some settings but ...
5
votes
Accepted
A Structure section with an entry to a channel index
I like what Matt P wrote in his answer:
try to consider how someone [else] will find the logic of the CMS design
The other factor you want to consider in information architecture is you only want ...
5
votes
Accepted
How to list out entry types in a section
Take a look at the sections documentation: https://craftcms.com/docs/templating/craft.sections
The following code lists all entrytypes of all sections.
{% set sections = craft.sections....
4
votes
Accepted
How do I create a link to an entry using entry's id?
The reason why your example fail is that you are using the entry variable. You are trying to call the function getUrl on the model entry, but the function (or model) doesn't exist yet, and has to be ...
4
votes
Accepted
How do you display entries in a specific (custom) order?
Try using a structure. You can reorder them in the CP.
{% for entry in craft.entries.section('your_structure') %}
{{ entry.title }}
{% endfor %}
4
votes
Accepted
How do I save a front-end form as a specific Entry Type?
This has been solved via a support ticket, which I'm posting here for others etc.
The first time you load the template, the URI is mapping to your "Get
A Quote" entry, which gets assigned to the ...
4
votes
Accepted
Pulling Data Across Entry Types
To access related entries stored in a matrix field, you need to specify the targetElement (actor/entry) and the matrix field (using dot syntax 'matrixFieldHandle.entriesFieldHandle') from 'plays'.
...
4
votes
Set Structure Parent when creating Entry in Plugin
This question is old, but the solution is:
// look up parent with a ElementCriteriaModel
$parentCriteria = craft()->elements->getCriteria(ElementType::Entry);
$parentCriteria->search = '...
4
votes
Looping through returns nothing after using dynamic routes to get the entry type and category
{% if not entries %} never executes, even if i enter complete nonsense in the url.
You’re not ensuring that segmentCategory is a valid category slug anywhere. If it’s not, then category will get set ...
4
votes
A Structure section with an entry to a channel index
Yes that makes sense. There are many ways to approach this. I always try to consider how someone other than me will find the logic of the CMS design i.e. How easy will they find Craft to actually use ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
entry-type × 97entry × 13
entries × 12
sections × 11
templating × 10
plugin-development × 8
url × 8
structure × 8
craft3 × 6
matrix × 5
routes × 5
categories × 4
assets × 3
control-panel × 3
search × 3
field × 3
conditional × 3
entrymodel × 3
channels × 3
best-practice × 3
admin × 2
filter × 2
forloop × 2
query × 2
redirect × 2