Home › Forums › Calendar Products › Events Calendar PRO › Display just category name
- This topic has 5 replies, 3 voices, and was last updated 7 years, 9 months ago by David.
-
AuthorPosts
-
July 11, 2016 at 10:45 pm #1138523DavidParticipant
Hi there,
This may have been answered already but if so, I can’t find it.
I’m doing some custom theming and am looking to display the category name on a page (in this case, “Training”)
I was able to use the following to output the venue and the time, and they worked fine:
Then I tried to use this to out put the event’s category:
And it echoes back:
Event Category:How do I just get it to echo back the word “Training” and nothing else (without any of the div, ul, li, a or any other tags) like the venue and address above do? I just need the event category name to display, no html tags at all.
Thanks for any help.
July 12, 2016 at 3:53 pm #1138923NicoMemberHey David,
Glad to help you out with this issue as well!
Let me start by saying that sp_get_venue is deprecated and should use tribe_get_venue instead. Also use tribe_get_address instead of sp_get_address. Regarding the categories in text format you can add the snippet below to your theme’s (or child theme’s) functions.php file:
if ( class_exists('Tribe__Events__Main') ){/* get event category names in text format */
function tribe_get_text_categories ( $event_id = null ) {if ( is_null( $event_id ) ) {
$event_id = get_the_ID();
}$event_cats = '';
$term_list = wp_get_post_terms( $event_id, Tribe__Events__Main::TAXONOMY );
foreach( $term_list as $term_single ) {
$event_cats .= $term_single->name . ', ';
}return rtrim($event_cats, ', ');
}
}
Once the code is in place you can call the function in the template: echo tribe_get_text_categories ();.
Please give a try and let me know if it works for you,
Best,
NicoJuly 13, 2016 at 1:07 pm #1139331DavidParticipantWorks perfect, just what I was looking for. Thanks Nico.
July 13, 2016 at 1:10 pm #1139332NicoMemberStocked to hear David, thanks for the heads-up 🙂
I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.
Best,
Nico -
AuthorPosts
- The topic ‘Display just category name’ is closed to new replies.