45

You can use MySQL's RAND() function inside your order method: {% for entry in craft.entries.section('team').type('mainPeople').order('RAND()') %}


27

You can either have MySQL select the blocks in a random order using RAND(): {% set blocks = entry.myMatrixField.order('RAND()') %} Or you can shuffle the blocks from Twig instead, using Craft’s shuffle() function: {% set blocks = shuffle(entry.myMatrixField) %} There’s not a major performance difference either way in most cases, however if you also want ...


18

I'd suggest changing the Recipe section to a "Structure" section type. This lets the client order the entries with a drag and drop from the Entries tab where they can see the whole list of entries during the reordering.


13

Read the article about ElementCriteriaModel in the official Craft docs on how to query elements in general and the craft.entries article about the parameter available to modify the object returned. Example code for your events list: {# Get events from `events` section in desired sort order #} {% set allEvents = craft.entries.section('events').order('...


12

There are several ways you could attack this, but probably the easiest is directly from the SQL side with something like this using a SQL CASE statement: {% set entries = craft.entries.section('news').order('(CASE WHEN field_alphaTitle IS NULL OR field_alphaTitle = "" THEN title ELSE field_AlphaTitle END)').find() %} <ul> {% for entry in entries %...


11

The primary parameter you're looking for is lft: craft.entries.section('volumes').order('lft desc')


9

This requires a bit of extra work on the ElementQuery, but it can be efficiently done in the same query. We first perform an inner join on the author's content table using the authorId so that the custom field is available to us. in Twig: {% set elementQuery = craft.entries() .section('sectionHandle') .with(['author']) .innerJoin('{{%content}} ...


8

You could try using use the reverse twig filter. {% for entry in craft.entries.section('volumes')|reverse %} ... {% endfor %}


8

You can do this entirely from the order param using MySQL’s CASE syntax: {% set newsItems = craft.entries({ section: 'news', order: '(CASE field_myLightswitchField WHEN 1 THEN elements.dateUpdated ELSE elements.dateCreated END) DESC' }) %} Note that you’ll need to include that “field_” prefix ...


8

My SuperSort plugin is built for use cases exactly such as this. It allows you to render each object in your array using a Twig object template and sort the array based on the rendered value.


8

Here's a solution using the group filter. {% set entriesGrouped = craft.entries.relatedTo(category).order('title')|group('myNewCategoriesField.first().title') %} {% for group in entriesGrouped %} {% for entry in group %} {# ... #} {% endfor %} {% endfor %}


7

This is based on Matt's answer to your previous question. Likewise this should better be used within cache tags! This is untested, but it hopefully works out for you. . Edit: This is still untested but it came to my ears, that it could make problems to assign variables as array keys. That's why I changed the code to use objects instead. If anyone uses ...


7

You're so close it's maddening—you should be able to order by a custom field as well: {% set assets = craft.assets.find({sourceId: 2, order: 'date desc'}) %} Where date is the name of your custom field. From the Craft docs (emphasis added): Possible values include 'title', 'id', 'sourceId', 'folderId', 'filename', 'kind', 'width', 'height', 'size', '...


6

Your statuses are incorrect. They would be correct for many elements, but the Entry Element overwrites them to the following: EntryModel::LIVE EntryModel::PENDING EntryModel::EXPIRED BaseElementModel::DISABLED


6

Give this a whirl, Mark: {% for image in craft.assets.relatedTo(tags).order('elements.dateCreated desc') %}


5

Short answer is, you can't. Long answer... Ian has some good advice, but the Post Date won't update automatically. Your best solution would be to update the Post Date every time you update something else in the entry. Then your Post Date will essentially represent your "last changed" date. Bonus answer... If/when you do build your own plugin, you can look ...


5

Alan, Without having tested this, you might get the desired result by using the group filter. So, get all you entries ordered by dateCreated, and then group them by category: {% set sermons = craft.entries.section('sermon').order('dateCreated desc').limit(null) %} {% for category, catSermons in sermons | group('categoryFieldHandle.first().title') %} &...


5

Your example is referencing a field that Twig doesn't know about yet. Also, you usually place the fields you are ordering entries with in quotes (ex: order('dateField')). Matrix blocks are elements (like so many things in Craft), and thus are unable to be used for ordering entries. THe reason is that the variable in the returned model is not the actual ...


5

I think the simplest solution is to use a plugin like Twig Better Sort or SuperSort. With those you would query for your entries as normal and then apply the Twig filter to sort the array. {% set entries = craft.entries.section('mySection') %} {% set entries = entries|supersort('natsortAs', '{title}') %}


5

No, that's not possible with Craft at the moment (2.4). You'll have to use the Field Layout Designer from Settings -> Sections -> {Section} -> {Entry Type} to manage your fields and tabs. You could always add a feature request if you feel this is something that should be included in the core.


4

I don't know if it's possible (but would like to see a query solution). There is one problem with your setup: If an entry gets a "substantial update", you can't make a correction afterwards, since it would become the latest item again. I propose you write a plugin which would: Wait for the 'onBeforeSaveEntry' event Check if the Lightswitch-field is "on" ...


4

You could try twig's reverse filter. {% for asset in entry.assetsField|reverse %} <img src="{{ asset.url }}" alt="{{ asset.title }}"/> {% endfor %}


4

Depending on your needs, you may be able to ditch the group() filter and sort your list however you need. Get all your entries and categories. Then use the relatedTo functions to filter those lists. {% set categories = craft.categories.group('projectCategories') %} {% set projects = craft.entries.section('projects').order('title').limit(null) %} {% for ...


4

Okay so you can either do this through ajax or through a page reload, a page reload is going to be much easier, but you can get it to work without reloading the page... Reloading the page You can basically make it so that when a user selects an option, use jQuery to redirect to the current page and append the <option> value to append as a query ...


4

Not exactly what you're looking for, but it gets you closer. This should display the order you want, but it doesn't have any pagination (and honestly I'm not sure if that's possible using Craft's {% paginate %} tag along with your other requirements. IMO, you're probably going to be better off doing this in PHP either using a Template Hook or a custom ...


4

The CpSortableCustomColumns plugin lets you sort your element index tables on custom fields. Sounds like it does exactly what you want.


4

This should work {% set entries = craft.entries({ section: 'news', sortOrder: 'postDate desc, lft asc', }) %}


4

This requires a bit of extra work on the ElementQuery, but it can be done in the same query. We need to perform an inner join on the relation between the movie and the show and then another inner join on the show's content table. Finally we can order on the custom field of the show's content table. {% set currentMovies = craft.entries() .section('...


4

I've seen that before, if you look at the sites table in your DB, you'll see that a few sites might have their sortOrder set to 1. If you go to Settings → Sites → [the offending group] in your Control Panel, try to reset the order of your sites in there (drag/drop using the little handle to the right of each site row), it should stop them showing up in a ...


3

My SuperSort plugin is built for use cases exactly such as this. It allows you to render each object in your array using a Twig object template and sort the array based on the rendered value. So, you could do something like: {% set sortedEntries = entries | supersort('sortAs', '{{ object.myLightswitch == 'y' ? object.dateUpdated: object.postDate }}') %}


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