Home › Forums › Calendar Products › Events Calendar PRO › How to use multiple templates for single events
- This topic has 3 replies, 3 voices, and was last updated 9 years, 10 months ago by
Brian.
-
AuthorPosts
-
June 24, 2016 at 8:57 am #1131520
scamrcalendar
ParticipantWe have customized the single-event.php page and it works wonderfully for the majority of our events. We do have a few times where there will not be an event, and we’d like to enter that on the calendar as well. (There normally would be 5 hikes every Wednesday, and if we only post 4 folks will ask why. If we can post a NO HIKE for the 5th hike that day, it will help eliminate confusion.)
So the question is: Is it possible to create a second single-event template, and use it when needed? If so, how do I use it? ie. there is no template dropdown box to select from.
Thought as I’m writing this: Is it possible to set up a hike category of NO HIKE, and then add code to the existing single-event.php such that it would first check the hike category and if it was NO HIKE, it would display “event body A”, otherwise, it would display “event body B”? How would I check the hike category in this case?
June 24, 2016 at 6:30 pm #1131798scamrcalendar
Participant1. Using the Advanced Custom Fields Plug-In, I created a custom field called is-there-a-hike. This has a field type of Select, and the options are 1 : YES and 0 : NO. The default value is set to 1 (yes), so I only have to change it in the no hike scenarios. Then in the Location section for this custom field (still in the ACF custom field), the “Show this field group if” is set as “Post Type is equal to tribe_events”. This way this custom field ONLY shows up if I am creating a calendar event – but it won’t show for any regular page or post work.
I set the Order No (under options right below the Location box) to 0 – so that it will be the first custom field to show for an event. That way, if there is no hike, I can select no on that field and be done quickly.
2. In my custom single-event.php file. This is stored in my child theme in a folder called tribe-events. DO NOT modify the original Tribe-events file.
Create a IF/THEN loop so that IF the is_there_a_hike custom field is set to 1 (YES), the information shows, and IF the variable is set to 0 (NO) then the info is hidden.
<!-- SHOW CONTENT ONLY IF THERE IS A HIKE --> <?php $ishike=get_field("is_there_a_hike")?> <!-- get value from custom field --> <?php if ($ishike == 1) {?> <!-- stuff you want to show when there is a hike (variable is set to 1 (yes)) goes here --> <?php } ; ?> <!-- END IF, SHOW SECTION ONLY IF HIKE THAT DAY -->I’m sure there are more glamorous ways to do this, but it works pretty slick.
June 25, 2016 at 7:57 am #1131879Brian
MemberI am glad to see you were able to figure it out.
We are limited in providing support on customizations, but this looks like a good solution for you.
Thanks for sharing your customization.
I am going to go ahead and close this ticket.
Thanks!
-
AuthorPosts
- The topic ‘How to use multiple templates for single events’ is closed to new replies.
