16

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


15

You can access the categories through the category field itself. {% for category in entry.categoryFieldHandle %} {{ category.title }} {% endfor %}


10

First, I would use something like training in your query string. It's a little more readable and you aren't searching for the words lunge and dumbbell anywhere in those entries, just entries related to those category slugs. {# First you would find any training categories in the URL query string. #} {% set trainingQuery = craft.request.getParam('training') %}...


9

That and argument only applies to the other top-level relatedTo arguments. If one of those arguments targets multiple elements (e.g. categories), those will still be glued together with “OR”. You would need to set it up like this instead: {% set resources = craft.entries.section('resources').relatedTo( 'and', { targetElement: category1 }, { ...


9

It'd be nice to see an example of your HTML block. From your comments it sounds like you may be using the same HTML block for Entry and Category pages but need to know which variable to use in the code. Assuming you know that your code is running on the Entry or Category pages, and that the fields across both your Entries and Categories for this part of the ...


6

Testing for the pre-populated variables is probably the only way to do this. But as you're asking for a single (global) var to test against, I believe you're looking for a way to have clean, dry code in your shared code block without using your posted snippet again and again. How about doing something like this: {% set entry = entry is defined ? entry : ...


6

A Categories field can be related to several categories. So you'll either need to limit your Category field to a single Category relationship or you'll need to make some assumption in how you build your URL as to which category will appear in the URL. The simplest assumption to make will be that you will always return the first category for your URL. Entry ...


6

You can use .relatedTo(category) {% for category in craft.categories.group('categoryName') %} <h2>{{category.title}}</h2> {% for entry in craft.entries.section('news').relatedTo(category) %} <a href="{{entry.url}}">{{entry.title}}</a><br> {% endfor %} {% endfor %} You can check for length if you don't want to show ...


5

To answer my own question see below: As carlcs pointed out correctly the problem actually isn't located in getting the category - which works just well and is the right way to do it - but in how the relation to the entries is done. I should check if the tag (coming from the url) actually resolves to a "real" category, otherwise just all entries will be ...


5

If might be your wording but I can see two potential answers here. You either want to list categories set through a category field on the entry, in that case the code Douglas has supplied will work perfectly. The other answer I can see is you have multiple categories that are assigned to an entry, and you want to list those categories out. If so, this will ...


5

With a little help I got there: {% set categories = craft.categories.group('developmentType').id('not ' ~ category.id) %} <ul> {% for category in categories %} <li><a href="{{ category.url }}" class="btn">{{ category }} Opportunities</a></li> {% endfor %} </ul>


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

Your mistake is in getting the category. Instead of what you have try: {% set category = craft.categories.group('allcategories').slug('photos').find() %} Getting elements in Craft use ElementCriteriaModel and find(), first(), last(), &c. do not accept any parameters (though nth() is an exception to this). So you need to search by other fields in the ...


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

In the CP, in the settings window for 'categories' you can set whether 'Categories in this group have their own URLs', and define the 'Category URL Formats' for categories and subcategories, and choose a category template. You could use {slug} for example, to route to the index page of the category (or whatever you want to use it for). Of course, you may not ...


4

I'd split the parameter string into an array and then loop through the categories and use a conditional to check if the value already exists in the parameter. It's not so easy to describe in detail, that's why I added lots of comments to the code (untested!). To work in your other parameters (size, etc.), simply add them to your links exactly how craft....


4

Here's the link to relevant the "Get Help" article: How do I list the entries related to a category? These really helpful tutorials are somewhat hidden on builtwithcraft.com, I overlooked them more than once while thought the normal Documentation articles! Just use the provided example code in your category loop: {% set entryIds = craft.entries.section('...


4

Try using the relatedTo() filter as explained here: http://buildwithcraft.com/help/entries-related-to-category {% paginate craft.entries.section('products').relatedTo(requestCategory).limit(9) as entriesOnPage %}


4

First you’ll need to grab the category ID from the query string, using craft.request.getQuery(): {% set catId = craft.request.getQuery('catId') %} Then you can fetch the CategoryModel via craft.categories and its id param: {% set category = craft.categories.id(catId).first() %} We can’t be sure that the ID was actually valid, so make sure that category ...


4

It depends how you're fetching the category. But if you've defined the template when setting up the categories it would be called be within a var called 'category', which would be a category object. You should then be able to access it using: {{ category.title }} If, on the other hand, you were getting the category via a slug in the URL, you would do ...


3

Not sure if you're still looking for an answer, but relation support has just been added to Super Table 0.3.7. Previously, relations wouldn't work with Super Table, as its a little bit of a special field, having sub-queries to perform for relations (each row). You can now query fields just like Matrix: {% set reverseRelatedElements = craft.supertable....


3

I'm not seeing any obvious ways to access groups directly in Twig. There may be a more direct way, idk — but this should work. {% set categoryGroupNames = [] %} {% for category in craft.categories %} {% set groupName = category.getGroup.name %} {% if groupName not in categoryGroupNames %} {% set categoryGroupNames = categoryGroupNames|merge([...


3

You probably did not yet come across this site: "Categories and Tags – Everything in its right place." Craft's explanation about Categories: You can set up Category Groups for managing different taxonomies within Craft, and then apply categories to other elements using a Categories field. And what they have to say about Tags: Craft has built-in ...


3

The Craft Categories page is very useful. To assign an entry to a category, create a category field, and require it in the entry type (you are probably already doing this). When you create a Category Group you can edit the field layout, and add an image field and a text field for the category. Then to edit that content, double click on the category itself (...


3

If you reverse the relationship then you should be able to order the entries (i.e. add products to an entries field within the category, instead of adding categories to a categories field within the product). So instead of grabbing the products using relatedTo(category), {% set products = craft.entries.section('products').relatedTo(category) %} {% for ...


3

Take a look at the {% exit %} tag. You should be able to do something very similar, since your search will return no results if the entry type does not exist. {% set entries = craft.entries.type(craft.request.getSegment(3)).relatedTo(category) %} {% if not entries %} {% exit 404 %} {% endif %}


3

I suggest changing the couple places where you use getParam('offerCategory') to getParam('category') so it matches the parameter set in the URL.


3

You're close! It's slightly counterintuitive but group is a property of a category. So you need to grab the group from an actual category. This would work: {% set catName = craft.categories.group('caseStudiesCategories').first.group %} Basically you're getting the first category in the group and grabbing the group name (you could also use [0] instead of ....


3

I figured it out! If anyone is stuck at the same place here’s my solution: {# category is 'ford' #} {% set entries = craft.entries.section('support').relatedTo(category).find() %} {% set partsCategories = craft.categories.group('partsGroup').relatedTo(entries) %} {# Partslist #} {% for partsCategory in partsCategories %} {{partsCategory.title}} {...


3

Turns out I was overthinking it, I was able to connect it with the following piece of code. {% set levelOne = category.topLevelConnection %} {% for subCat in craft.categories.group('levelTwo').relatedTo(levelOne) %}


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