Home › Forums › Calendar Products › Events Calendar PRO › Adding Custom Field to List View
- This topic has 7 replies, 3 voices, and was last updated 10 years, 8 months ago by
Support Droid.
-
AuthorPosts
-
August 20, 2015 at 3:01 pm #997723
flourishdesignstudio
ParticipantI have followed the video instruction (http://tri.be/pro-adding-custom-events-attributes/) and successfully created a custom field for our events. What I am having trouble doing is then adding that field to the list view. If it is helpful to view our progress so far you can see it here: http://009.3b2.myftpupload.com/events/ and the event has has this field included in the details is here: http://009.3b2.myftpupload.com/event/coltivare-cider-dinner/
For events where there is a reservation required (that is the custom field I added) we would like it to show on the event list under the google map link. Is this possible? Can you point me in the right direction?
Also, is it possible to have the date display as “Tuesday, October 6” instead of “October 6”?
Thanks!
AnnaAugust 21, 2015 at 5:50 am #997868George
ParticipantHey Anna,
Thanks for reaching out!
Custom Field Beneath Maps Link
You can indeed add code to your site and force it to come after that “+ Google Map” link. There are two basic approaches: first is to find any template file within The Events Calendar and Events Calendar Pro that call the function tribe_get_map_link_html() – this is the function that generates that map. Then, using the principles outlined in our Themer’s Guide, add your custom-field code beneath this function call.
The second approach, and maybe simpler, is to just add a filter to the tribe_get_map_link_html filter so that your custom-field code is automatically added after each instance of “+ Google Map”. You can do this by adding a function like this to your theme’s functions.php file:
add_filter( 'tribe_get_map_link_html', 'tribe_997723_append_custom_fields_to_map' );function tribe_997723_append_custom_fields_to_map( $link ) {
ob_start();
tribe_get_template_part( 'pro/modules/meta/additional-fields', null, array(
'fields' => tribe_get_custom_fields(),
) );
$fields = ob_get_clean();return $link . '<br>' . $fields;
}
If this function doesn’t provide enough flexibility for your needs, unfortunately the previously-mentioned method using our Themer’s Guide is the only other reliable option 🙁
Change the Date Display
Also, is it possible to have the date display as “Tuesday, October 6″ instead of “October 6″?
This is indeed possible – can you specify exactly what location of the date display you’re referring to? Just curious, but 99 times out of 100 the default Date Format Settings within The Events Calendar’s settings panel will address these needs for you.
Basically, head to Events > Settings > Display in your sites wp-admin. Scroll down to find the Date Format Settings, which look like this: https://cloudup.com/cBatDxYorvN
Now, notice the link in the top-right of this section? It tells you to make your own date format which you can learn here: http://codex.wordpress.org/Formatting_Date_and_Time
If that looks confusing, don’t worry – it’s actually really easy (and a bit fun 🙂 ) to play around with.
For example, to go from “October 6” to “Tuesday, October 6”, find date format patterns that are like this: “F j”. And just add the lowercase-“L” which symbolizes the day name in PHP date formatting. So replace all cases of “F j” with this: “l, F j”. The comma will be used there, so this pattern will become {Weekday Name}, {Month Name} {Day Number}.
I hope that all makes sense! Definitely check out the materials I’ve linked to in this thread, as they’re full of great info.
Let me know if this helps and/or if you have any further questions, thoughts, etc.
Cheers,
GeorgeAugust 21, 2015 at 8:42 am #997965flourishdesignstudio
ParticipantHi George,
Thanks for the helpful reply! The date part is great and I have never had to work on that before so I appreciate your explanation and patience! It was such an easy fix!
Okay, so for adding the custom field into the event list view I am hoping we can just modify the code you sent and instead add it to List > single-event.php file so that it will display in the list view. I like where it shows up in the Single Event page and just want to change it it the list view.
Here is the live link: http://009.3b2.myftpupload.com/events/
Here is the code that I *think* will work (the part that pull in the venue name, address, and map link:
<?php echo tribe_get_venue() ?> <span class="delimiter"> | </span> <?php // This location's street address. if ( tribe_get_address( $venue_id ) ) : ?> <span class="street-address"><?php echo tribe_get_address( $venue_id ); ?></span> <?php if ( ! tribe_is_venue() ) : ?> <?php endif; ?> <?php endif; ?> <?php // This locations's city. if ( tribe_get_city( $venue_id ) ) : if ( tribe_get_address( $venue_id ) ) : ?> <span class="delimiter">,</span> <?php endif; ?> <span class="locality"><?php echo tribe_get_city( $venue_id ); ?></span><span class="delimiter">,</span> <?php endif; ?> <?php // This location's abbreviated region. Full region name in the element title. if ( tribe_get_region( $venue_id ) ) : ?> <abbr class="region tribe-events-abbr" title="<?php esc_attr_e( $full_region ); ?>"><?php echo tribe_get_region( $venue_id ); ?></abbr> <?php endif; ?> <?php // This location's postal code. if ( tribe_get_zip( $venue_id ) ) : ?> <span class="postal-code"><?php echo tribe_get_zip( $venue_id ); ?></span> <?php endif; ?> <br> <?php echo tribe_get_map_link_html(); ?> <?php echo tribe_997723_append_custom_fields_to_map(); ?>Would adding that last line of PHP accomplish what I am trying to do? Is there a way to make it only appear if the input is a specific value (such as if the event requires registration then the field will appear but if not then it will not show up).
I realize I am new to php editing so thank you for the great resources and your help!
Anna
August 24, 2015 at 5:01 pm #998611George
ParticipantHey Anna,
That code may indeed work well for you – if you’re new to editing code, be sure to have backups of everything of course!
Both of our approaches should work similarly. Note that in mine, I’m adding the fields directly to the tribe_get_map_link_html filter, so my code just echos its contents right after that function. Now, look at your code. It literally does the same thing, just a bit more literally, and if you wanted to add more HTML then your method would make that easier to do.
So it’s really up to you – both should work fine.
Keep good backups of everything, and play around a bit. I’m sure you’ll be able to put something useful together!
Cheers,
GeorgeAugust 25, 2015 at 6:23 am #998726flourishdesignstudio
ParticipantThanks George!
We are almost there! If you go to the link you will notice that the second event does require reservations and it is appearing under the google map link in the list view: http://009.3b2.myftpupload.com/events/
However, now it also appear by the google map link on the individual event page too, which we don’t want. Is there any way for me to just add it to the list veiw only? I had tried to add in the single line of code
<?php echo tribe_get_map_link_html(); ?>but that didn’t work. Any thoughts?
Also, if reservations ARE required is it possible to simply have a statement that says:
“Reservations Required”instead of:
Other
Are Reservations Required?
yesThank you so much for your help! I reall yappreciate it!
August 25, 2015 at 6:46 am #998735flourishdesignstudio
Participantoops, sorry… the code was supposed to be:
<?php echo tribe_997723_append_custom_fields_to_map(); ?>but still isnt working
-
This reply was modified 10 years, 8 months ago by
flourishdesignstudio.
August 25, 2015 at 5:25 pm #999005George
ParticipantHey Anna,
You can indeed use event conditional tags to only run the code in certain places – check out a list of conditionals here: https://gist.github.com/jo-snips/2415009
Play around with those, hopefully you can get it working as you desire.
September 9, 2015 at 7:05 am #1003238Support Droid
KeymasterThis topic has not been active for quite some time and will now be closed.
If you still need assistance please simply open a new topic (linking to this one if necessary)
and one of the team will be only too happy to help. -
This reply was modified 10 years, 8 months ago by
-
AuthorPosts
- The topic ‘Adding Custom Field to List View’ is closed to new replies.
