Get event category when viewing category page

Home Forums Calendar Products Events Calendar PRO Get event category when viewing category page

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1078248
    excaladmin
    Participant

    When viewing an event category page (i.e. mydomain.com/events/category/category-name), I am trying to detect the event category to which the events on the page belong. I have code in place that detects when a page is an event category page, and it works well. So I am able to detect that I’m on a category page, but I cannot figure out how to retrieve the event category itself. How would I do this? I have spent a lot of time searching and trying different things, but I can’t seem to successfully retrieve the category.

    The reason I am looking to do this is because I want to display a different logo image on the page depending on what the category is.

    I did have the thought that I could try parsing the page’s URL for the category slug, but I’d prefer a less ugly – and more robust – method if possible.

    Thanks,

    Ben

    • This topic was modified 10 years, 2 months ago by excaladmin.
    • This topic was modified 10 years, 2 months ago by Brian.
    #1079735
    Brian
    Member

    Hi,

    Thanks for using our plugins. I can help out here.

    I found this guide is good at showing how to getting term information:

    http://www.wpbeginner.com/wp-themes/how-to-show-the-current-taxonomy-title-url-and-more-in-wordpress/

    Add this to the template with a conditional to run what you would like:

    $term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );

    if ( isset( $term->slug ) && $term->slug == 'concert' ) {
    //run code
    }

    Let me know if you have any follow up questions.

    Thanks

    #1080715
    excaladmin
    Participant

    Thank you Brian! I was able to use the example code you posted to do what I needed to do.

    Ben

    #1080717
    Brian
    Member

    Great, glad it helps, I am going to go ahead and close this ticket, but if you need help on this or something else please post a new ticket.

    Thanks!

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Get event category when viewing category page’ is closed to new replies.