2

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

4

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. – Mark Notton Nov 18 '14 at 9:43
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);
  }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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