Show subcategories in category view

Home Forums Calendar Products Events Calendar PRO Show subcategories in category view

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1152477
    Marlene Hassel
    Participant

    Is there a way to do that?

    #1152805
    Nico
    Member

    Hi Marlene,

    Thanks for getting in touch! Nice mock up šŸ˜‰

    What you are looking for is possible with a bit of custom code, I can help you get started with this:

    /* Tribe subcategory nav for photo view */
    function tribe_add_subcategories ( ) {

    global $wp_query;

    // bail if the function is not defined or we are not in photo view or if no event category is set
    if ( !function_exists('tribe_is_photo') || !tribe_is_photo() || !isset( $wp_query->query_vars[ Tribe__Events__Main::TAXONOMY ] ) ) return false;

    $termparent = get_queried_object();
    $termchildren = get_term_children( $termparent->term_id, Tribe__Events__Main::TAXONOMY );

    // bail if no children
    if ( empty($termchildren) ) return false;

    // display children
    echo '

      ';
      foreach ( $termchildren as $child ) {
      $term = get_term_by( 'id', $child, Tribe__Events__Main::TAXONOMY );
      echo '

    • ' . $term->name . '
    • ';
      }
      echo '

    ';

    }

    add_action( 'tribe_events_after_the_title', 'tribe_add_subcategories' );

    Paste the code above in your theme’s (or child theme’s) functions.php file and give it a try šŸ™‚

    Best,
    Nico

    #1153037
    Marlene Hassel
    Participant

    Thanks!

    2 more things:

    • I’d like to show the subcategory events in their respective subcategories only, and not in the parent category.
    • Would it be possible to give each subcategory a featured image so that they can be displayed in the same way as the events?
    #1153481
    Nico
    Member

    You are welcome Marlene!

    Iā€™d like to show the subcategory events in their respective subcategories only, and not in the parent category.

    Sure, try this updated version of the snippet instead:

    /* Tribe subcategory nav for photo view */
    function tribe_add_subcategories ( ) {

    global $wp_query;

    // bail if the function is not defined or we are not in photo view or if no event category is set
    if ( !function_exists('tribe_is_photo') || !tribe_is_photo() || !isset( $wp_query->query_vars[ Tribe__Events__Main::TAXONOMY ] ) ) return false;

    $termparent = get_queried_object();
    $termchildren = get_term_children( $termparent->term_id, Tribe__Events__Main::TAXONOMY );

    // bail if no children
    if ( empty($termchildren) ) return false;

    // display children
    echo '

      ';
      foreach ( $termchildren as $child ) {
      $term = get_term_by( 'id', $child, Tribe__Events__Main::TAXONOMY );
      echo '

    • ' . $term->name . '
    • ';
      }
      echo '

    ';

    }

    add_action( 'tribe_events_after_the_title', 'tribe_add_subcategories' );

    Would it be possible to give each subcategory a featured image so that they can be displayed in the same way as the events?

    Yes, this functionality can be added with a plugin: Category and Taxonomy Image, Easy Taxonomy Images, Taxonomy Images, etc.

    Please let me know if there’s anything else I can do for you,
    Best,
    Nico

    #1162131
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Show subcategories in category view’ is closed to new replies.