<p><strong>Plugin alternative:</strong> </p>

<pre><code>  public function statusIsLive($handle) {
    $section = craft()-&gt;sections-&gt;getSectionByHandle($handle);
    $criteria = craft()-&gt;elements-&gt;getCriteria(ElementType::Entry);
    $criteria-&gt;section = $section;
    return craft()-&gt;elements-&gt;findElements($criteria);
  }
</code></pre>

CC BY-SA 3.0
2014-11-18T09:44:19.557Z
2014-11-18T09:44:19.557Z
Mark Notton
<p>This should work. </p>

<pre><code>{% set policy = craft.entries.section('policy').first() %}
{% if policy %}&lt;a href="{{ policy.url }}"&gt;{{ policy.title }}&lt;/a&gt;{% endif %}
</code></pre>

<p><code>ElementCriteriaModel</code> should only return active records by default.</p>

CC BY-SA 3.0
2014-11-18T09:43:17.497Z
Thanks Douglas, this is great. It worked and put me in the right direction to create a Plugin alternative too.
Mark Notton
CC BY-SA 3.0
2014-11-17T17:36:33.317Z
2014-11-17T17:36:33.317Z
Douglas McDonald
<p>This is probably a really basic question, but I can't figure out how to check the status of a page before I link to it. </p>

<p>I have a link in my footer to 'Policy' page. But if the page status is inactive, I don't want that link to show. How can I perform this simple check?</p>

<p>Thanks,</p>

<p>Mark</p>

<templating><navigation><conditional>
How to link to a page, but only if the page status is active
# How to link to a page, but only if the page status is active

(Asked by: username_0 on 2014-11-17)

This is probably a really basic question, but I can't figure out how to check the status of a page before I link to it.

I have a link in my footer to 'Policy' page. But if the page status is inactive, I don't want that link to show. How can I perform this simple check?

Thanks,

Mark

**Tags:** templating, navigation, conditional


---

## 2 answers

### Answer by username_1 on 2014-11-17. Score: 4 | Accepted answer

This should work. 
{% set policy = craft.entries.section('policy').first() %}
{% if policy %}{{ policy.title }}{% endif %}

ElementCriteriaModel should only return active records by default.

> **Comments:**
> **username_0**: Thanks Douglas, this is great. It worked and put me in the right direction to create a Plugin alternative too.  

---

### Answer by username_0 on 2014-11-18. Score: 0

Plugin alternative: 
  public function statusIsLive($handle) {
    $section = craft()->sections->getSectionByHandle($handle);
    $criteria = craft()->elements->getCriteria(ElementType::Entry);
    $criteria->section = $section;
    return craft()->elements->findElements($criteria);
  }


---

