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?



2 Answers 2


This should work.

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

ElementCriteriaModel should only return active records by default.

  • Thanks Douglas, this is great. It worked and put me in the right direction to create a Plugin alternative too. Nov 18, 2014 at 9:43

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.