13
votes
9
votes
Accepted
Check if paginate
The paginate.totalPages variable will give you the total number of pages that are generated by the paginate tag. So you can wrap your display of pages around a conditional that checks to see if this ...
6
votes
Accepted
How can I show 3 entries at random from within the next 10
You could use Craft's shuffle() function to randomize your postDate ordered array of entry models:
{% set entries = craft.entries({
section: 'entertainmentEvents',
entertainmentBanner: ':...
6
votes
Accepted
Impossible to invoke a method ("limit") on an array... but it's not an array?
I'm not calling .all(), so this is still an object, right?
Nope. When you execute the for loop, it will explicitly run the database query and return the array of results. You're probably getting a ...
5
votes
Accepted
When using .limit on matrix blocks they don't show in live preview
I noticed the same issue with live preview, but using the type property on the Matrix field: Issue with Matrix type property and Live Preview? According to Brandon's answer this is a current bug / ...
5
votes
Accepted
A more economical method of building an archive menu?
If you know which years should appear, and there are no breaks in the timeline, perhaps it would make more sense to do a simple numeric loop instead...
{% for year in (now.year)..2009 %}
{{ year }...
5
votes
How to limit number of entries returned from a group filter?
The reason limit() isn't working is that is a method on the ElementCriteriaModel you get from craft.entries.
Because you're actually dealing with a standard array when you access catEntries, what ...
5
votes
Matrix max block type limit
I just published a plugin called Limit Block Type, which adds the ability to limit Matrix blocks per block type.
There's also a feature request for adding this feature to core.
4
votes
Accepted
Matrix - using Limit on block types
You can limit which blocks you want by type and only show the first of each, if they exist. Something like this might do the trick:
{% for entry in craft.entries.section('blog').limit(3).find() %}
...
4
votes
Accepted
Only display entries based on a field conditional
I highly recommend to use the fantastic Preparse plugin to save to length of your body text in a hidden field.
Create and add a new "bodyLength" Preparse field to your "Artists" entry type. Use this ...
4
votes
Accepted
Default Craft entry limit
As of Craft 3, there is no limit by default.
Per the CHANGELOG:
Element queries are no longer limited to 100 results by default.
(Credit to Ben Croker who originally added this answer as a comment ...
4
votes
Accepted
For loop does not display all entries in section
Craft has a default limit of a 100 elements returned via an ElementCriteriaModel. To pull all elements, you'll need to explicitly set limit to null:
{% for post in craft.entries.section('posts')....
4
votes
Accepted
Get next 3 upcoming entries
What you do, is this:
Get 30 items from the database, ordered by showTime
Then, you filter them with the if-attribute in the for-statement
This means, that you could get anywhere from 0 to 30 ...
3
votes
Accepted
Can't add anymore fields / blocks to Matrix Field
There's nothing in Craft limiting the amount of Matrix Blocks and fields you can add, it's purely environmental.
The most common values to increase are max_input_vars, post_max_size and memory_limit, ...
3
votes
ElementAPI: How to order and/or limit results?
Just setting the limit property doesn’t do the trick alone, you need to deactivate pagination, too:
'criteria' => [
'section' => 'trucks',
'limit' => 10,
'orderBy' => '...
3
votes
How can I limit the output of assets randomly if an asset exists?
This is how you do it in case anyone is looking for this.
{% set assets = craft.assets.limit(null) %}
{% set randomEntry = craft.entries.section('homes').order('RAND()').relatedTo({
...
3
votes
Accepted
Unable to sort large number of blocks in Matrix field in CP and template
This is because Craft stores the sortOrder values in the database with a MySQL column type of tinyint that happens to be signed, which means it can store a range of -128 to 127.
Aside from the fact ...
3
votes
Only display entries based on a field conditional
You could do something like this:
{# Grab all entries with a body > 100 %}
{% for entry in craft.entries.section('artists').order('RAND()').find() if entry.body|length > 100 %}
{# Limit output ...
3
votes
Accepted
Offset setting a limit?
When you're setting section.links.limit(4), Craft will persist that limit in subsequent calls.
This was a change introduced in Craft 3, which you can read about Changes in Craft 3 | Cloning Element ...
3
votes
Offset setting a limit?
Joshua M's answer explains why it's happening, but in terms of best practice, you'd be better off avoiding multiple roundtrips to the database by using Twig filters on a single result set. There are ...
2
votes
Accepted
Matrix max block type limit
Reading your description I see no reason to not use all three fields in a single matrix block. If you need additional control (e.g. for positioning the title), you could add another field to that ...
2
votes
Check if paginate
The above doesn't display any paging even when there is paging. It needs to be pageInfo not paginate:
{% if pageInfo.totalPages > 1 %}
{# output current pages and pagination navigation here #}...
2
votes
Querying channel entries hits memory limit
Assuming you're referring to Craft 2, the EntryModels that get returned to a template do have a significant memory overhead attached to them you're probably running into. Doing the math, even bumping ...
2
votes
Accepted
How can I pull every entry (large number) in a section?
You could use the {% paginate %} tag with ajax to limit the number of entries that are pulled at a time.
2
votes
Accepted
ElementAPI: How to order and/or limit results?
This should do the trick:
'criteria' => [
'section' => 'trucks',
'limit' => 10,
'order' => 'title asc',
]
The Element Criteria Model documentation has more information ...
2
votes
Accepted
Querying channel entries hits memory limit
Read some pages in the craft docs that Brad linked to get to know the basic structure where to place your files
Go to Pluginfactory and create a plugin, you only have to check the "Variables" light ...
2
votes
Accepted
Allowing the user to update a CraftCMS pagination limit with listing filter options
You could create a form/a link with the limit and add the parameter in your $_GET request or as a segment to your url. This is just an example how to use it.
How many Entries would you like to get?
&...
2
votes
Accepted
Update field setting value using getFieldByHandle
MY SOLUTION
Use setAttributes and set the second argument $safeOnly to false
$fieldsService = Craft::$app->getFields();
$field = $fieldsService->getFieldByHandle('productImages');
// Update '...
2
votes
Accepted
Date Limit on Element Query
Have you tried
.renewalDate('and', ">= #{dateStart}", "< #{dateEnd}")
The difference is the double quotes. I don't think that single quotes support interpolation.
However, I'm not sure in ...
2
votes
Restricting file size for an Assets Volume
There's no way for the moment to limit filesize by Volume, but your can create a custom module with the EVENT_BEFORE_SAVE hooked on Assets.
Here's a related post.
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
limit × 35entries × 7
templating × 6
matrix × 5
forloop × 5
assets × 3
conditional × 3
pagination × 3
database × 2
entry × 2
field × 2
elementcriteriamodel × 2
query × 2
upload × 2
category × 2
elementquery × 2
blocks × 2
block-types × 2
plugin-development × 1
categories × 1
plugin-elementapi × 1
datetime × 1
image × 1
error × 1
sections × 1