$49

Ad Wizard

Documentation  •  Changelog

Documentation

Get ads with an Element Query

In addition to the prepackaged `displayAd` and `randomizeAdGroup` functions, it's also possible to collect a set of ads through an Element Query.

{% for ad in craft.adWizard.ads.group('rightSidebar') %}

    {# Do something creative with ads #}
    {{ ad.displayAd() }}

{% endfor %}

or:

{% set ads = craft.adWizard.ads.group('rightSidebar').orderBy('RAND()') %}

This is the same basic mechanism which allows you to get entries, assets, and categories in Twig. And just as you would with entries, you can apply "all", "one", or "ids" to the end.

.onlyValid()

By default, an Element Query for Ads will return all matching results, whether the ads are valid or not. However, it's possible to filter out all invalid ads by simply chaining the .onlyValid() command anywhere in your query.

{% set ads = craft.adWizard.ads.group('rightSidebar').onlyValid() %}