• Resolved dankfresh

    (@dankfresh)


    I know this is something very simple I’m overlooking, but I’m modifying the single.php template file to display different things based on the category I place it in.

    I’ve tried using

    <?php tribe_meta_event_cats(); ?>

    which returns the label and link as well. Passing parameters does nothing for me, for some reason.

    I just want to get the category name or slug, while still in the loop, and store it as a variable. Many thanks!

    https://www.ads-software.com/extend/plugins/the-events-calendar/

Viewing 15 replies - 1 through 15 (of 16 total)
  • Thread Starter dankfresh

    (@dankfresh)

    Well, I accomplished a little something….

    I would prefer the slug, but I duplicated + renamed the tribe_meta_event_cats(); function (located in plugin /public/template-tags/general.php) to this :

    function tribe_meta_event_cats_short( $label=null, $separator=', ')  {
    	if( !$label ) { $label = __('', 'tribe-events-calendar'); }
    	$tribe_ecp = TribeEvents::instance();
    	$list = apply_filters('tribe_meta_event_cats', get_the_term_list( get_the_ID(), $tribe_ecp->get_event_taxonomy(), '', $separator, '' ));
    	return strip_tags($list);
    	}

    The important thing is it returns the category name(s) and I used strip_tags() to remove the links. Then, on my single.php page, I store that to a variable and echo it whenever I please. I’m sure there is a better way to accomplish though….

    Hi there dankfresh. Thanks for the note here; glad to hear you’ve made some progress. I’m asking Jonah from our team to take a look here – while this is outside my area of expertise, he may have some advice that can point you in the right direction. Stay tuned and thanks for your patience so far.

    Hi dankfresh,

    You should be able to use get_the_terms() instead:

    $terms = get_the_terms(get_the_ID(), 'tribe_events_cat');
    	$count = count($terms);
    	if ( $count > 0 ){
    		foreach ( $terms as $term ) {
    	    		echo $term->slug;
    		}
    	}

    Does that help?

    Hey there dankfresh, just wanted to follow up on this one. Do you need anything else from us or is Jonah’s solution enough to get you where you need to be? Let me know and we can follow-up as needed. Thanks!

    Thread Starter dankfresh

    (@dankfresh)

    Hey roblagatta. Yes, thank you for following up! Excellent support.

    Excellent to hear! Thanks for confirming, dankfresh – glad to be of service. If you find yourself needing anything else in the future, please just let us know. Otherwise thanks again for your use of The Events Calendar.

    How would I add a comma separator to Jonah’s code?

    Hi flint_and_tinder,

    You could do something like this:

    $terms = get_the_terms(get_the_ID(), 'tribe_events_cat');
    	$count = count($terms);
    	if ( $count > 0 ){
    		foreach ( $terms as $term ) {
    	    		echo $term->slug;
                            if ( $count > 1 ) {
                                echo ', ';
                            }
    		}
    	}

    Sorry should have mentioned, I also need to exclude a category used by my homepage slider. So far I have this:

    <?php $terms = get_the_terms(get_the_ID(), 'tribe_events_cat');
            $count = count($terms);
            foreach ( $terms as $term ) {
                        if($term->term_id != 3) { // the term ID you want to exclude
                        echo $term->slug;
                }
            }?>

    I would suggest using https://codex.www.ads-software.com/Function_Reference/get_categories instead then.

    – Jonah

    Thanks but can’t be arsed to re-code. I’ll do without.

    Okie dokie.

    Quick unrelated question; what details do I use to login to the PRO forums?

    Whatever details were sent to you when you purchased the plugin. If you don’t remember them you can try clicking on the Forgot Password link.

    Only thing sent was order receipt containing links to wp-admin, but all ok, I’m in now.

Viewing 15 replies - 1 through 15 (of 16 total)
  • The topic ‘[Plugin: The Events Calendar] Echo Category Name’ is closed to new replies.