58

You are probably not using this within a craft.entries loop. Position it inside a loop or set custom parameters for your prev and next elements: {# Set parameters for prev/next elements list #} {% set params = craft.entries.section('blog').order('title asc') %} {# Get the prev/next elements #} {% set prevEntry = entry.getPrev(params) %} {% set nextEntry = ...


29

The trick is to add and once before the first not {% set entries = craft.entries.search(query).section('and, not this, not that') %}


19

You can set the prev.url at the top of the template, for example: {% set criteria = {section: 'blog', order: 'postDate'} %} {% set prev = entry.getPrev(criteria) %} Add a link if prev is available: {% if prev %} <a href="{{ prev.url }}">{{ prev.title }}</a> {% endif %}


18

BaseElementModel::getContent() will return the element’s ContentModel. It has two purposes: To store the element’s data from the craft_content table table when fetching elements from the DB. To store the POST data that should be stored in the craft_content table when saving an element to the DB. In both cases, the ContentModel should not actually be ...


16

This got it working for me: /section/{categoryFieldName.first.slug}/{slug}


10

I found the clue for how to do this in the getPrevSibling documentation: getPrevSibling() will return the previous sibling whether or not it’s enabled. If you want to get the closest enabled sibling, you can do this instead: {% set prevSibling = craft.entries.positionedBefore(entry).order('lft desc').first() %} So this query will get the number of ...


7

You are correct in stating that Records typically define a new custom table for your plugin. However, don't forget that Craft already comes with many pre-existing Records. Take a look inside this folder: /craft/app/records Although based on your question (and the ensuing comments thread), it looks like you may not need to tap directly into any Records at ...


7

There's a positionedBefore parameter for craft.entries. Use this with a criteria model filtered to show the entries you are interested in only. {% set parent = entry.getParent() %} {% set siblingsIds = parent.getChildren().ids() %} {% set positionedBefore = craft.entries({ id: siblingsIds, order: 'lft desc', positionedBefore: entry, }).total() %...


7

Records are definitely not the way to go with dealing with large amounts of data sets in the database. There is just too much overheard associated with them. Manually running SQL (as you've discovered) is an option, but if you wanted to do this from PHP, you could still use QueryBuilder. $elementIds = craft()->db->createCommand() ->...


6

You are close, instead of checking entry|length, you can do {% if entry is defined %} {% if entry is defined and entry.sectionId == 1 %} So if I am understanding correctly, the full code will be: {% if entry is defined and entry.sectionId == 1 %} // Redirect to homepage {% else %} // Do some checking into whether there's a corresponding entry, ...


6

This is a longer version answer (code wise) to the one Douglas already posted. He did a very nice job of explaining how to get a URL parameter and what to pay attention to handling the results. I will try to show you how to build a query from multiple unknown params, so any of these combinations is possible and potentially return a single (and unique) Entry ...


6

To set a related category (or any other kind of element) you will want to pass an array of categoryIds (elementIds) — even if, as in this case, there is only one category or element. You can either set the ID as a static value if it's predefined or dynamically look it up based on the title, slug or any other unique element attribute. $criteria = craft()->...


5

You need to create the field in the CMS, however you don't need to assign it to any section. It should still be available to your plugin and twig templates. The other reason your code will result in an error is because $entry->secretName is in fact being processed by the BaseElementModel magic getter method, so is the same as writing $entry->...


5

You can access 'post' or 'get' parameters using craft.request.getParam('param'); and then use them to retrieve the corresponding entry. So, given the URL: http://example.com/subsection/filename.html?id="170" In your template, you would grab the param 'id', and use it to retrieve the entry. {% set entryId = craft.request.getParam('id') %} {% set entry = ...


5

You should process your two POST parameters differently. One is responsible for your search parameter in your results template and the other should go into a relatedTo parameter. That's why I recommend to get them separately (it's probably not even possible to get them with a single getParam, but I'm not sure). Here's how I'd proceed with the category ...


5

ContentModel will only have the values in the actual content table, and the values that are actually there still may not be what you’re after, because accessing those values directly won’t give the field types a chance to do any preprocessing on their data. So the best way to reliably get an array of all of an element’s custom field content is to go through ...


5

The proper conditional statement in this case would be to test for the length property of your Asset field, i.e. cover: {% if cover | length %} The reason this works, is that calling slide.coverImage will – as long as the attribute "coverImage" exists for the "slide" model – never return a falsey value, even if there are no files. It will in fact always ...


5

Indeed... EntryModel->revisionNotes is what you're looking for. Through PHP, that's: $entry->revisionNotes Through a template, that's: {{ entry.revisionNotes }}


5

Update - Craft 3 This has been fixed. The relational field will retain its original value when an entry is re-saved. You no longer need to apply a workaround to get the expected behavior. Original - Craft 2 This is, admittedly, super awkward right now. To prevent a relational field from losing its value when saving an entry, you have to explicitly set ...


5

Actually, entry.getLocales() (or just entry.locales) will return an array of the locales enabled for the entry's section, not all locales in the system. Unfortunately, there's no easy way to determine which locales a single entry is enabled for. One way to do it, is to use a craft.entries query per locale, and add the locale ids to an array whenever you get ...


4

getContent() will return the element’s ContentModel, NOT getContent()->merchant, which is just an attribute of the ContentModel—sorry for the confusion. I’ve just posted a separate Q&A fully explaining what the ContentModel is used for here: What is getContent() / the ContentModel, and how do I use it to get and set custom field values? What you ...


4

As I understand it, you want the url for an entry to be /section/category-slug/entry-slug. This is a little tricky, because if the entry has no category defined, it won't have a url, which is why you can't just set the Entry URL Format. If you really want to do this, you can do it using routes rather than the entry URL format. Uncheck the Entries in this ...


4

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'. In your actor biography template: Actor: {{ entry.title }}<br><br> {% set plays = craft.entries.section('plays').relatedTo({ targetElement: ...


4

{% 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 to null, which will basically prevent it from affecting the following relatedTo param. So right after grabbing the category you should make sure it exists; {% ...


4

This is in no means an elegant solution, and can almost certainly be improved. But it did its job just fine. {% set veterinarians = craft.entries({ section: 'veterinarians', order: 'premiumVet desc, postDate desc', }) %} {# more filter/search params #} {% set entriesPerPage = 20 %} {% set page = craft.request.getParam('page') %} {% set page = page ...


4

Filtering entries is now possible as of Sprout Forms v2.2.0: {% for formEntry in craft.sproutForms.entries.formHandle('contact').firstName('Zoe') %} ... {% endfor %#}


4

setContentFromPost() performs an operation on the attached ContentModel, not on the element model itself. When you initialize a BaseElementModel, its content attributes are set from the associated ContentModel. ("Content attributes" means attributes from custom field data, a.k.a. the stuff you'll typically find in the craft_content DB table for a given ...


4

Have you considered to cache the whole output? https://craftcms.com/docs/templating/cache


4

Caching will improve performance, but the actual issue is that your code is generating a lot of queries. You should look into eager loading: https://craftcms.com/docs/templating/eager-loading-elements The basic idea is that you predefine what sub-elements you're going to need (in your case gig_artist and gig_venue), so that Craft can preload them instead ...


3

I've been able to modify the entry editing form by creating a plugin that will include some javascript into CP layout. Then with javascript, I use some checks to make sure that I'm in the right place before doing any adjustments. For example, in the following code, I checked if I'm editing an entry within section 32, then the label of postDate field will be ...


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