Home › Forums › Calendar Products › Events Calendar PRO › Conditionally display Additional Field, or customize Additional Field URL?
- This topic has 5 replies, 2 voices, and was last updated 11 years ago by
Brian.
-
AuthorPosts
-
February 19, 2015 at 8:17 am #943687
Sean Sullivan
Participant[Looked through previous related threads but couldn’t find an answer to my question.]
I have a few Additional Fields in my events; they display in a custom-built Nivo Slider through WP_Query.
The fields won’t always be used, and I’d only like them displayed when a value has been entered (e.g., there’s one for a Facebook link, one for a Buy Tickets link, etc.).
I’d initially set the field as a “URL”. With a value of http://facebook.com, it outputs this HTML:
<a target="self" href="http://facebook.com">http://facebook.com</a>The good: If no value is entered, nothing is displayed. The bad is that it doesn’t allow me to style the link or add a class. I’d prefer an output of:
http://facebook.com… so I could wrap it in a
<a>tag.So, I figured I’d just set the additional fields as Text. That gets me a plain value of
http://facebook.comspit out. Here’s the code I’m using:<a class="slider-facebook-link" href="<?php $additional_fields = tribe_get_custom_fields(); echo $additional_fields['Facebook Event Link'];?>">Facebook</a>Is this the best way to achieve what I’d like? If so, how can I set a conditional to only display the field if it has a value?
My attempt is:
<?php if($additional_fields = tribe_get_custom_fields(['Facebook Event Link'])) { ?> <a class="slider-facebook-link" href="<?php $additional_fields = tribe_get_custom_fields(); echo $additional_fields['Facebook Event Link'];?>">Facebook</a> <?php } ?>February 19, 2015 at 8:18 am #943688Sean Sullivan
ParticipantSorry, that first code block should have read:
<a target="self" href="http://facebook.com">http://facebook.com</a>February 19, 2015 at 8:19 am #943691Sean Sullivan
ParticipantI’m not sure how I’m linking code wrong. Again, that first code block should be: http://facebook.com
February 19, 2015 at 8:27 am #943694Sean Sullivan
ParticipantOK, so, I guess the support forum is wrapping all links in tags, even if they’re in code blocks, which has made the first half of my post super confusing.
Please just ignore the first half and skip down to the line that starts: “Here’s the code I’m using:”
February 19, 2015 at 2:39 pm #943782Brian
MemberHi,
Thanks for using the Events Calendar. I can help out here.
Best way to share code a lot of the time is through Pastebin (can do it without an account) or as a Gist.
I think I got what you are trying to do.
Try this instead:
<?php
$additional_fields = tribe_get_custom_fields();if ( $additional_fields['Facebook Event Link'] ) { ?>
tribe_get_custom_fields() returns an array for all additional fields.
Use that once then you can echo the value for any of your fields by adding the name:
<?php echo $additional_fields['Facebook Event Link']; ?>Let me know if that works for you.
Thanks
March 30, 2015 at 8:18 am #951907Brian
MemberSince there is has not been any activity on this thread for over 2 weeks so I am now closing it. Feel free to start a new thread if you have further issues. Thanks! 🙂
-
AuthorPosts
- The topic ‘Conditionally display Additional Field, or customize Additional Field URL?’ is closed to new replies.
