Add venue based class to body

Home Forums Calendar Products Events Calendar PRO Add venue based class to body

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1515932
    Benedikt
    Participant

    Hey there!
    I want to add the venue nicename to my body class and change the background depending on the venue the event is listed for. The event overview body however needs to be untouched.
    My Problem: The venue classes are all added up to the body whenever the overview “events” is opened. So all bodys are being loaded. I found a solution, but im not sure if its really stable – Im not in to php to be honest.

    
    add_filter('body_class','conf_class');
    function conf_class($classes) {
    
        $post_id = get_the_ID(); 
        $venue = tribe_get_venue($post_id); 
    
    if (is_tax()){ 
    	$venue = 'myVenue-' . $venue;
      $classes[] = $venue;
      return $classes;
    } else {return $classes;}
    }
    

    My questions on this peace of code:

    – I added “is_tax()” because it ocures to me, that “events” page has no custom taxonomies – can I ask for specific taxonomies like string “category nicename” here? Would be better I guess. something like “if is_tax(“category name”).

    – In the end I had to return the untouched classes. If I dont return them, some classes go missing (like for closed tribe filter bar). Is that correct?

    • This topic was modified 8 years ago by Benedikt.
    • This topic was modified 8 years ago by Benedikt.
    #1517039
    Victor
    Member

    Hi Benedikt!

    Thanks for getting in touch with us! I’d be happy to help you with this topic.

    First, please let me note that we are fairly limited in how much support we can give for custom development questions like that.

    That said, we always like helping out and at least point users into the right direction as much possible.

    The venues are not a taxonomy, but a custom post type. Just to clarify I understand what you are trying to accomplish, you need to are looking to add a class to the body tag with the venue name, but only for venue pages. Is that correct?

    Please let me know about it and I’ll try to come up with a working snippet for you.

    Thanks,
    Victor

    #1517669
    Benedikt
    Participant

    Dear Victor, thanks for your reply and for closing the copy of this threat!

    I absolutely understand that there have to be limitations for the support of personalisation – so tell me if I got to far :). In the last weeks your support was able to help me with all of my requests, so Im very positive!

    I need to change the background for certain venues, not for the event overview pages.
    Venue x : Background X
    Venue y: Background Y
    Overview (all venues): background neutral.

    add_filter('body_class','conf_class');
    function conf_class($classes) {
    
        $post_id = get_the_ID(); // I guess thats not needed anymore
    	$v1 = '8995'; //venue ID 1
    	$v2 = '1444'; //venue ID 2
        $venue = tribe_get_venue(); 
    	if ($venue == $v1 || $v2){ 
    	$venue = 'myVenue-' . $venue; // class name which is added to body 
      	$classes[] = $venue;
    	  return $classes;
    	}else {return $classes;}} // if nothing has happened, go on and return the body classes as is
    

    My problem still is: The “events overview pages” stick to one of those backgrounds and dont show a neutral background. The reason is simple: in my case the request for venue is connected to a post ID. I suppose WordPress asks for the venue of the first post in a row and pulls the background for the venue ID. That works on one venue only pages. Whenever we access an overview, the background for the first post venue is pulled – but thats not what I want :).

    Sorry, nor my english or my programming skills are that good.

    • This reply was modified 7 years, 12 months ago by Benedikt.
    #1517789
    Victor
    Member

    Hi Benedikt!

    Thanks for clearing that out.

    I you only want to change the background for specific venues, you can do so with a CSS snippet, because the post ID is already printed in the body tag.

    For example, you can paste the following CSS snippet into your theme’s styles or using the WordPress customizer (WP Admin > Appearance > Customize > Additional CSS)

    .single-tribe_venue.postid-25 .site-content-contain {
    background-color: #ddd;
    }

    This will apply a background color to the the venue for which the post ID is 25.

    It may still need a tweak depending on the theme you’re using, so if you have trouble making it work, just share with us a link to the venue page and I will try to help you with it.

    Best,
    Victor

    #1518901
    Benedikt
    Participant

    Okay. Ill give that a try,
    thanks!

    #1519301
    Victor
    Member

    You are welcome Benedikt! Thanks for following up.

    I’ll go ahead and close this thread now, but feel free to open a new topic if anything comes up and we’ll be happy to help.

    Cheers,
    Victor

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘Add venue based class to body’ is closed to new replies.