WordPress.org

Forums

The Events Calendar
[resolved] Echo Category Name (17 posts)

  1. dankfresh
    Member
    Posted 2 years ago #

    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!

    http://wordpress.org/extend/plugins/the-events-calendar/

  2. dankfresh
    Member
    Posted 2 years ago #

    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....

  3. Rob La Gatta
    Modern Tribe Support
    Plugin Author

    Posted 2 years ago #

    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.

  4. jonahcoyote
    Member
    Posted 2 years ago #

    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?

  5. Rob La Gatta
    Modern Tribe Support
    Plugin Author

    Posted 2 years ago #

    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!

  6. dankfresh
    Member
    Posted 2 years ago #

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

  7. Rob La Gatta
    Modern Tribe Support
    Plugin Author

    Posted 2 years ago #

    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.

  8. flint_and_tinder
    Member
    Posted 2 years ago #

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

  9. jonahcoyote
    Member
    Posted 2 years ago #

    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 ', ';
                            }
    		}
    	}
  10. flint_and_tinder
    Member
    Posted 2 years ago #

    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;
                }
            }?>
  11. jonahcoyote
    Member
    Posted 2 years ago #

    I would suggest using http://codex.wordpress.org/Function_Reference/get_categories instead then.

    - Jonah

  12. flint_and_tinder
    Member
    Posted 2 years ago #

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

  13. jonahcoyote
    Member
    Posted 2 years ago #

    Okie dokie.

  14. flint_and_tinder
    Member
    Posted 2 years ago #

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

  15. jonahcoyote
    Member
    Posted 2 years ago #

    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.

  16. flint_and_tinder
    Member
    Posted 2 years ago #

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

  17. Rob La Gatta
    Modern Tribe Support
    Plugin Author

    Posted 2 years ago #

    Fantastic to hear you're all set on this end too, flint_and_tinder. (Thanks, Jonah, for your help.)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • The Events Calendar
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic