Answers.Body: <p>You can use <code>{{ craft.entries.section('whatever').total() }}</code> for that.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-15T13:17:46.040Z
Answers.Text: For some reason `.total()` is slower than `.limit(1) | length`, by ~10ms on average. And also this is only testing when there are 1 or 0 active entries.
Answers.UserDisplayName: peirix
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-15T13:20:39.300Z
Answers.Text: That's a cool tip. Did you compare it to Jeremy's suggestion?
Answers.UserDisplayName: Fred Carlsen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-16T14:09:39.880Z
Answers.Text: Yeah, that was about the same as `.limit(1) | length`, so actually faster than `total()`
Answers.UserDisplayName: peirix
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-12T09:12:40.023Z
Answers.LastActivityDate: 2017-05-12T09:12:40.023Z
Answers.UserDisplayName: Fred Carlsen
Answers.Body: <p>Not a definitive answer at all, but you could at least add a <code>.ids()</code> on that so it only retrieves the entry ids and not all the entry data...</p>
  
  <pre><code>{% if craft.entries.section('whatever').ids() | length &gt; 0 %}
  &lt;a href="www.com"&gt;Go here&lt;/a&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-12T08:23:50.903Z
Answers.Text: Would this be better than doing `.section().first.id`?
Answers.UserDisplayName: peirix
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-16T09:27:30.943Z
Answers.Text: `.section().first.id` will break if there is no ids.
Answers.UserDisplayName: Fred Carlsen
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-05-12T08:21:44.457Z
Answers.LastActivityDate: 2017-05-12T08:21:44.457Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>Just wondering what the most efficient way to check whether a section has any entries or not. Based on this, I'm showing some content. The content doesn't take any information from the entries in the section, so it'll be a superfluous query no matter what.</p>
  
  <p>For context, this is basically what it'll look like:</p>
  
  <pre><code>{% if craft.entries.section('whatever') | length &gt; 0 %}
      &lt;a href="www.com"&gt;Go here&lt;/a&gt;
  {% endif %}
  </code></pre>
  
Tags: <entries><sections><query>
Title: Most efficient way to check if a section has any active entries
ThreadText: # Most efficient way to check if a section has any active entries
  
  (Asked by: username_0 on 2017-05-12)
  
  Just wondering what the most efficient way to check whether a section has any entries or not. Based on this, I'm showing some content. The content doesn't take any information from the entries in the section, so it'll be a superfluous query no matter what.
  
  For context, this is basically what it'll look like:
  
  ```
  {% if craft.entries.section('whatever') | length > 0 %}
      <a href="www.com">Go here</a>
  {% endif %}
  
  ```
  
  **Tags:** entries, sections, query
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2017-05-12. Score: 4 | Accepted answer
  
  Not a definitive answer at all, but you could at least add a `.ids()` on that so it only retrieves the entry ids and not all the entry data...
  
  ```
  {% if craft.entries.section('whatever').ids() | length > 0 %}
  <a href="www.com">Go here</a>
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: Would this be better than doing `.section().first.id`?  
  > **username_1**: `.section().first.id` will break if there is no ids.  
  
  ---
  
  ### Answer by username_1 on 2017-05-12. Score: 6
  
  You can use `{{ craft.entries.section('whatever').total() }}` for that.
  
  > **Comments:**
  > **username_0**: For some reason `.total()` is slower than `.limit(1) | length`, by ~10ms on average. And also this is only testing when there are 1 or 0 active entries.  
  > **username_1**: That's a cool tip. Did you compare it to username_2's suggestion?  
  > **username_0**: Yeah, that was about the same as `.limit(1) | length`, so actually faster than `total()`  
  
  ---
  
  