Answers.Body: <p>The category field returns an <a href="https://craftcms.com/docs/templating/elementcriteriamodel" rel="nofollow noreferrer">ElementCriteriaModel</a>, which means you can use all the methods that you'd usually use to get a specific category on it.</p>
  
  <p>For instance, if the category field is named <code>entryCategories</code>, and you know the slug of the category you want to test for, you could do:</p>
  
  <pre><code>{% if entry.entryCategories.slug('my-category-slug').total() %}
      Do something
  {% endif %}
  </code></pre>
  
  <p>Or you could use the <code>id</code>the same way. </p>
  
  <p>Please note, this does not work if the entryCategory field was eager-loaded, since <code>entry.entryCategories</code> would then return an array. In that case you could just loop over the array and have a check inside for loop that checks the category you're looping over is the correct one. A bit dirty, but it does the job. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-14T17:59:16.240Z
Answers.Text: @MatthewCarleton I just updated the answer to exchange the `length` filter for the more efficient `total()` method. Instead of querying the category models it just queries for the count of rows in the database. The query itself is quicker and it also uses much less memory.
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-14T17:03:48.127Z
Answers.LastActivityDate: 2016-11-14T17:56:43.667Z
Answers.LastEditDate: 2016-11-14T17:56:43.667Z
Answers.UserDisplayName: André Elvan
Body: <p>I have an entry page that lists out specific info for a product. I am using categories to sort the entries. I'm trying to figure out how to write a conditional that pulls in something specific if the entry belongs to a specific category.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-14T16:51:20.760Z
Comments.Text: So, you have a categories-field on the entry, and if a specific category is selected, you want to do something?
Comments.UserDisplayName: André Elvan
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-14T16:55:04.657Z
Comments.Text: ya, in the entry you can select the category it's in and so I want to display something for entries that belong to a certain category.
Comments.UserDisplayName: Matthew Carleton
Tags: <categories>
Title: Category conditionals
ThreadText: # Category conditionals
  
  (Asked by: username_0 on 2016-11-14)
  
  I have an entry page that lists out specific info for a product. I am using categories to sort the entries. I'm trying to figure out how to write a conditional that pulls in something specific if the entry belongs to a specific category.
  
  **Tags:** categories
  
  > **Comments:**
  > **username_1**: So, you have a categories-field on the entry, and if a specific category is selected, you want to do something?  
  > **username_0**: ya, in the entry you can select the category it's in and so I want to display something for entries that belong to a certain category.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-11-14. Score: 3 | Accepted answer
  
  The category field returns an [ElementCriteriaModel](https://craftcms.com/docs/templating/elementcriteriamodel), which means you can use all the methods that you'd usually use to get a specific category on it.
  
  For instance, if the category field is named `entryCategories`, and you know the slug of the category you want to test for, you could do:
  
  ```
  {% if entry.entryCategories.slug('my-category-slug').total() %}
      Do something
  {% endif %}
  
  ```
  
  Or you could use the `id`the same way.
  
  Please note, this does not work if the entryCategory field was eager-loaded, since `entry.entryCategories` would then return an array. In that case you could just loop over the array and have a check inside for loop that checks the category you're looping over is the correct one. A bit dirty, but it does the job.
  
  > **Comments:**
  > **username_2**: @username_0 I just updated the answer to exchange the `length` filter for the more efficient `total()` method. Instead of querying the category models it just queries for the count of rows in the database. The query itself is quicker and it also uses much less memory.  
  
  ---
  
  