Syntax needed for conditional code within Event List shortcodes
WordPress Event Management, Calendars & Registration › Forums › General Question › Syntax needed for conditional code within Event List shortcodes
This topic contains 4 replies, has 2 voices, and was last updated by Stephen Harris 4 years ago.
-
AuthorPosts
-
June 19, 2022 at 5:24 am #41319
I have submitted this query 3 times already, and it looks like 3 times have failed.
I’m able to “reply” to my own apparently empty query yet the forum software keeps vapourising, the body of my query, apparently.
I have a saved copy… so I’m now going to try stripping the markup and resubmitting… to finally get through on here.
Vicki Taylor
June 19, 2022 at 5:40 am #41322Hi, Stephen,
I’ve already attempted to submit this query so many times, but it keeps getting blocked… so I keep stripping markup, hoping to clean it up enough to “go in”. Fingers crossed it works this time!
I’m getting tremendous mileage from the event_list %event_organiser_url% code you gave me – https://wp-event-organiser.com/forums/topic/event-list-shortcode-include-organiser-wp-username-linking-website/. I use it in various lists with the format tweaked for specific event categories. Great!
Thank you! šAlas, Iām still not very code-clue-ful, so I need a tiny bit more help with conditional code. In some lists, I mix more-than-one category, and want to mix organisers: with, and without, %event_organiser_url%
So in this example:
[eo_events event_category=”introduction,intermediate,review” showpastevents=”true” event_start_after=”first day of january this year” event_end_before=”first day of january next year” no_events=”No events announced at present”]%start{j F}% – %end{j F}%: [%event_title%] led by [%event_organiser%][/eo_events]Please give me the syntax for these 3 conditions:
1) IF event_category=”introduction,intermediate”, show:
led by [%event_organiser%]
if event_category=”review”, don’t show it.2) IF %event_organiser% is exactly “some-user”, don’t show: led by [%event_organiser%]
but for the remainder, show it.3) AND IF other users’ %event_organiser_url% is not empty, show:
led by [%event_organiser%]
otherwise, only show: led by %event_organiser%Thanking you in advance for all your very kind help!<br />
VickiVicki Taylor
June 24, 2022 at 12:27 am #41356Hi Vicki,
Apologies that your posts kept being blocked.
Unfortunately the templating doesn’t extend to supporting conditional logic. This can be done in PHP. Specifically if you use the shortcode without any templating and then copy the file
event-organiser/template/shortcode-event-list.phpinto your theme, and edit line 48.Something like the following should work (although I’ve not tested it):
<?php $event = get_post(); $event_organiser = get_user_by( 'id', (int) $event->post_author ); $event_organiser_url = esc_url($event_organiser->user_url); printf( "%s - %s: %s", eo_get_the_start( "j F" ), - eo_get_the_end( "j F" ), get_the_title()) if ($event_organiser->user_login != "some-user" && ! has_term("review", "event-category") ) { if (empty($event_organiser_url)) { printf( " led by %s", esc_html($event_organiser->display_name)); } else { printf( " led by <a href="%s">%s</a>", $event_organiser_url, esc_html($event_organiser->display_name)) } } ?>Stephen Harris
June 24, 2022 at 12:28 am #41318Hi, Stephen,
I’ve already attempted to submit this query twice, but it seems both times failed, so here I go again!
I’m getting tremendous mileage from the event_list %event_organiser_url% code you gave me – https://wp-event-organiser.com/forums/topic/event-list-shortcode-include-organiser-wp-username-linking-website/. I use it in various lists with the format tweaked for specific event categories. Great! Thank you! š
Alas, Iām still not very code-clue-ful, so I need a tiny bit more help with conditional code.
In some lists, I mix more-than-one category, and organisers with and without URLs.
So in this example:
[eo_events event_category="introduction,intermediate,review" showpastevents="true" event_start_after="first day of january this year" event_end_before="first day of january next year" no_events="No events announced at present"]<strong>%start{j F}% - %end{j F}%:</strong> <a href="%event_url%">%event_title%</a> <em>led by <a href="%event_organiser_url%">%event_organiser%</a></em>[/eo_events]Please give me the syntax for these 3 conditions?
1) IF event_category=”introduction,intermediate”, show:
<em>led by <a href="%event_organiser_url%">%event_organiser%</a></em>if event_category=”review”, don’t show it.
2) IF %event_organiser% is exactly “some-user”, don’t show:
<em>led by <a href="%event_organiser_url%">%event_organiser%</a></em>but for the remainder, show it.
3) AND IF other users’ %event_organiser_url% is not empty, show:
<em>led by <a href="%event_organiser_url%">%event_organiser%</a></em>otherwise, only show:
<em>led by %event_organiser%</em>Thanking you in advance for all your very kind help!
VickiVicki Taylor
June 24, 2022 at 12:29 am #41358Hi Vicki,
Looks like our messages crossed. I had seen your earlier post but it had been marked as ‘pending’ by the forum.
Does my answer help at all?
Stephen Harris
-
AuthorPosts