Sometimes you want info only to be shown dependant on some conditions. In almost all formatting settings, you can use a special shortcode called [events_if] that allows these kind of decisions:
You can use all placeholders in the if-part, just by prepending them with “ESC”, e.g you could use this for single event formatting:
#j, #M #Y – #H:#i
#_NOTES
[events_if tag='#ESC_ATT{color}' value='red'] color: #_ATT{color} [/events_if][events_if tag='#ESC_ATT{price}'] price: #_ATT{price} [/events_if][events_if tag='#ESC_TOWN'] the town is: #_TOWN [/events_if][events_if tag="#ESC_ATT{Image URL}"] [/events_if][events_if tag="#ESCj #ESCM #ESCY" value="#ESC@j #ESC@M #ESC@Y"] The start and end date of this event is the same, so just showing start: #j #M #Y [/events_if][events_if tag="#ESC_{j M Y}" value="#ESC@_{j M Y}"] The start and end date of this event is the same: #j #M #Y [/events_if][events_if tag="#ESC_{j M Y}" notvalue="#ESC@_{j M Y}"] This date is only printed if different from start date: #@_{- j M Y} [/events_if]
The possible conditions you can test for are:
- Nothing, you then just check that the placeholder/string mentioned in the
tagis not empty:[events_if tag='#ESC_TOWN'] is_empty=1checks that the placeholder/string mentioned in thetagis in fact empty:[events_if tag='#ESC_TOWN' is_empty=1]valuechecks if the placeholder/string mentioned in thetagis the same as the one mentioned invalue:
[events_if tag='#ESC_ATT{color}' value='red']color: #_ATT{color}[/events_if]notvaluechecks if the placeholder/string mentioned in thetaghas a value different than the once mentioned invalueltchecks if the numerical value of the placeholder/string mentioned in thetaghas a value lower than than the once mentioned inltgtchecks if the numerical value of the placeholder/string mentioned in thetaghas a value bigger than than the once mentioned ingtcontainschecks if the value of the placeholder/string mentioned in thecontainsoccurs in the once mentioned intagnotcontainschecks if the value of the placeholder/string mentioned in thenotcontainsdoesn’t occur in the once mentioned intag
As extra, next to the regular placeholders you can use, I added some extra shortcodes:
- #_IS_SINGLE_EVENT (’1′ if you’re viewing a single event details, ’0′ otherwise)
- #_IS_SINGLE_LOC (’1′ if you’re viewing a single location details, ’0′ otherwise)
- #_IS_LOGGED_IN (’1′ if user is logged into WP, ’0′ otherwise)
- #_IS_ADMIN_PAGE (’1′ if on the admin pages, ’0′ otherwise)
- #_IS_PRIVATE_EVENT (’1′ if the event is a private event, ’0′ otherwise)
- #_IS_RSVP_ENABLED (’1′ if the event is RSVP-able, ’0′ otherwise)
- #_IS_SINGLE_DAY (’1′ if you’re viewing a single day, ’0′ otherwise)
- #_IS_REGISTERED (’1′ if WP user has already registered for the event, ’0′ otherwise)
Example usage:
[events_if tag='#_IS_LOGGED_IN' value='0'] You are NOT logged in [/events_if]
[events_if tag='#_IS_LOGGED_IN' value='1'] You are logged in [/events_if]
[events_if tag='#ESC_CATEGORIES' contains='red'] The event is in at least the red category [/events_if]
[events_if tag="#ESCj #ESCM #ESCY" value="#ESC@j #ESC@M #ESC@Y"] The start and end date of this event is the same, so just showing start: #j #M #Y [/events_if]
A variant of the above, using curly brackets:
[events_if tag="#ESC_{j M Y}" value="#ESC@_{j M Y}"] The start and end date of this event is the same: #{j M Y} [/events_if]
Print start date, and print end date only if different:
#_{j M Y} [events_if tag="#ESC_{j M Y}" notvalue="#ESC@_{j M Y}"] #@_{- j M Y} [/events_if]
Using this conditional tag requires some playing around …
I also added [events_if2] and [events_if3], if you want to use more than one level of logic (wordpress doesn’t like a shortcode with the same name enclosed in another one)