Hot answers tagged

13

Set the limit to null limit(null).


9

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 is greater than 1. {% if paginate.totalPages > 1 %} {# output current pages and pagination navigation here #} {% endif %} More details, including a ...


6

You could use Craft's shuffle() function to randomize your postDate ordered array of entry models: {% set entries = craft.entries({ section: 'entertainmentEvents', entertainmentBanner: ':notempty:', status: 'live, pending', order: 'postDate desc', limit: 10 }) %} {% set entries = shuffle(entries) %} {% for entry in entries|slice(0, 3) %...


5

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 }} {% endfor %} That will count backwards from the current year to 2009.


5

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 / limitation of the Matrix field that you have to find a workaround for. In this case this is rather easy, get all the blocks and use the slice filter to loop over ...


5

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 you want instead is Twig's |slice(start, length) filter: {% for entry in catEntries|slice(0, 4) %} // You'll only get four entries shown here {% endfor %}


5

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

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() %} <div class="col-8 {% if loop.last %}last{% endif %}"> {% set textBlock = entry.blogBody.type('text').first() %} {% set imgBlock = ...


4

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').limit(null) %} ... {% endfor %}


4

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 results. What you want to do, is make sure the filtering happens within the element query. I did not test this (not sure about the time criteria part), but something ...


4

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 deprecation error logged using that syntax as well since Craft wants you to use {% for album in albums.all() %} See here in the docs: https://docs.craftcms....


3

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, so you'd need to bump one or more of those to higher values to be able to add more. If you're running things like Suhosin or mod_security, they provide their ...


3

Just setting the limit property doesn’t do the trick alone, you need to deactivate pagination, too: 'criteria' => [ 'section' => 'trucks', 'limit' => 10, 'orderBy' => 'title asc', ], 'paginate' => false,


3

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({ targetElement: assets, field: 'homeImages' }) %} {% for homesEntry in randomEntry.limit(6) %} {% set asset = homesEntry.homeImages.first() %} {% if asset %} ...


3

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 that negative sort orders don't make much sense, that means if you have 127 or more Matrix blocks to sort, things will stop working as expected. Because 127 ...


3

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 Twig code in the field settings: {{ entry.body|length }} To update all existing entries, re-save them by going into Settings → Sections → Artists and click ...


3

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 to the first 4 #} {% if loop.index1 <= 4 %} {{ entry.id }}'s body field has a length greater than 100!<br /> {% endif %} {% endfor %} ...


3

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 Queries You have two options to resolve your issue: Use clone() to create a new version of the ElementCriteriaModel for each time you use section.links {% for ...


3

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 probably a few different ways, but here's one using slice: {% set allLinks = section.links.all() %} {% for link in allLinks|slice(0, 3) %} {# iterate ...


2

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 block that allows you to set your settings (e.g. a dropdown with "Title left" / "Title right" options). If you really need a per block type limit (now), you could ...


2

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 #} {% endif %}


2

You could use the {% paginate %} tag with ajax to limit the number of entries that are pulled at a time.


2

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 switch to generate a PluginNameVariables file Download the files and place them in your craft/app/>>pluginHandle<< folder like it is stated in the ...


2

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 your php.ini memory_limit up to 256M is only going to get your around 260 results coming back with your given fields/configuration. It's one of the big things ...


2

This should do the trick: 'criteria' => [ 'section' => 'trucks', 'limit' => 10, 'order' => 'title asc', ] The Element Criteria Model documentation has more information about setting criteria. Update for Craft 3.x* The “order” element query param has been deprecated. Use “orderBy” instead. * Craft v3.0.11 reports this in the /...


2

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? <a href="/?limit=10">10</a> <a href="/?limit=20">20</a> <a href="/?limit=30">30</a> Then you can fetch this parameter {% ...


2

MY SOLUTION Use setAttributes and set the second argument $safeOnly to false $fieldsService = Craft::$app->getFields(); $field = $fieldsService->getFieldByHandle('productImages'); // Update 'limit' value to be empty in order to accept as many images as needed $field->setAttributes([ 'limit' => '' ],false); $fieldsService->saveField($...


2

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 that case why the version without the 'and' works. OK, have just tried it myself... I created a section called test and added a single date field called ...


2

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.


1

Somehow you would just need to communicate to your template that you are changing the default limit. A fairly simple/standard way is through a query string, and then looking for the value of the variable. The two things you need to accomplish are Setting the query string if someone changes the dropdown box Checking for a value of the query string key in ...


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