Body class conflict with The Events Calendar Pro

Home Forums Plugin Integration Body class conflict with The Events Calendar Pro

This topic is: not resolved

This topic contains 9 replies, has 4 voices, and was last updated by  Rob Yardman 4 years, 9 months ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2887

    onelittlemoose
    Participant

    Working with Events Calendar Pro. For context, I strongly encourage review of this post:

    http://tri.be/support/forums/topic/body-classes-for-individual-event-categories/

    Short summary: body classes for the event categories were not being written properly.

    However I believe I’m wrong that it’s a problem with Events Calendar, rather it’s Thematic’s body classes. I installed a test child theme of twentytwelve, and sure enough, the body classes were correct (specifically “events-category-whats-happening-in-lake-dief” as they should be). Switching back to my Thematic child theme, I commented out these bits:

    define(‘THEMATIC_COMPATIBLE_BODY_CLASS’, true);
    define(‘THEMATIC_COMPATIBLE_POST_CLASS’, true);

    Sure enough, the body classes are written correctly again. So it appears there is a problem with the my Thematic body classes.

    I would leave it as is, but unfortunately I’m getting body classes only in the post categories and event categories. The individual posts, individual events, and pages are body class-less, at least for my purpose.

    I understand that the last 2 releases of Thematic worked with the body classes, and that ultimately we should be using WordPress’s own body class functionality. Would that address this? And if so is there a relatively easy way to replace Thematic’s body classes with WP’s?  Even one that I could figure out?  I fear I may start drinking soon, with no class.

    Not sure if this question belongs in the Plugin forum, or the child theme forum. It’s a problem that’s been revealed by a plugin, but it does not appear to be the plugin itself.

    As always, thanks. Hugely.

    #2888

    Scott Nix
    Moderator

    You should just be able to remove the Thematic added classes by removing the lines of code completely from your child theme, or commenting them out.

    
    // define(‘THEMATIC_COMPATIBLE_BODY_CLASS’, true);
    // define(‘THEMATIC_COMPATIBLE_POST_CLASS’, true);

    In the newest Thematic version, these are deprecated and considered legacy features, so they are no longer used, way back in the day they provided more classes than WP offered, but now WP offers plenty of hooks to work with. 😛

    #2889

    onelittlemoose
    Participant

    Thanks for the reply, Scott.

    I have commented out those lines, and the category archives are fine, but the problem is I lose the body classes in the individual posts, and the pages.  Those are the parts I need to get back, but don’t know how.

    #2890

    Scott Nix
    Moderator

    Are you using the latest version of Thematic?

    The only other thing I can think of is you have taken the header.php file from Thematic and pasted it into your child theme.

    In the header file the body class is called with

    
    // Create the body element and dynamic body classes
    thematic_body();
    
    

    Then it adds the standard body class, since it is called in the header, it should be the same on every page….

    
    /**
    * thematic_bodyopen function
    */
    function thematic_bodyopen() {
    if ( apply_filters( ‘thematic_show_bodyclass’,TRUE ) ) {
    // Creating the body class
    echo &#8216;<body ';
    body_class();
    echo '>&#8216; . &#8220;\n\n&#8221;;
    } else {
    echo &#8216;<body>&#8216; . &#8220;\n\n&#8221;;
    }
    }

    If it isn’t that, there has to be something in your functions.php or a theme file if you have pasted any of the original files into your child theme. You possibly could change the theme from your child them to Thematic and checking to see if they are there also.

    #2891

    onelittlemoose
    Participant

    I went back and checked, and my Thematic version is 1.0.3.2. I downloaded it again, taking the clean functions.php suggested from the child theme within the latest version. Same thing. Category archives get the body class, but pages and individual posts do not.

    The functions.php file shows the body class part commented out:

        // add_theme_support( ‘thematic_legacy_feedlinks’ );
    // add_theme_support( ‘thematic_legacy_body_class’ );
    // add_theme_support( ‘thematic_legacy_post_class’ );
    // add_theme_support( ‘thematic_legacy_comment_form’ );
    // add_theme_support( ‘thematic_legacy_comment_handling’ );

    I then changed the theme to Thematic itself. Same problem.

    Specifically for what it’s worth, the body class from an individual post is this:

    single single-post postid-998 single-format-standard logged-in admin-bar mac firefox ff18 customize-support

    No indication there of its category.

    Page body class looks like this:

    page page-id-363 page-template-default logged-in admin-bar mac firefox ff18 customize-support

    (have compared the child theme vs original thematic, and output is the same)

    Got no class.

    I am baffled. Is there perhaps some kind of filter I need to write?

    Much obliged.

    #2892

    Scott Nix
    Moderator

    I can’t for the life of me figure out why they would be different. I know Thematic grabs browser info and appends that to the class names which is totally useless and dumb. Reminds me I need to push to get that crap removed. 😡

    So… I guess if all you are needing is to add certain classes. I would suggest to add them manually based on the ID of the post or page. Looks like you already know how to find that. 😛

    
    function childtheme_body_class( $classes ) {
    
    if ( is_single( ‘168’ ) ) { // post ID
    $classes[] = ‘custom-class’;
    } elseif ( is_page( ‘823’ ) ) { // page ID
    $classes[] = ‘custom-class’;
    }
    return $classes;
    }
    add_filter( ‘body_class’, ‘childtheme_body_class’ );
    
    /*
    
    Twenty Twelve – Single Post – single single-post postid-168 single-format-standard logged-in admin-bar no-customize-support custom-font-enabled”
    Thematic – Single Post – single single-post postid-168 single-format-standard logged-in admin-bar no-customize-support custom-background full-width windows firefox ff18
    
    Twenty Twelve – Single Page – page page-id-823 page-template page-template-template-page-archives-php logged-in admin-bar no-customize-support custom-font-enabled
    Thematic – Single Page – page page-id-823 page-template page-template-template-page-archives-php logged-in admin-bar no-customize-support custom-background custom-class windows firefox ff18
    
    */
    
    

    If that doesn’t solve it, I may need to actually call on someone who is a PHP wizard (which I am not).

    #2894

    middlesister
    Keymaster

    Congratulations, you have stumbled upon a bug. Unfortunately, having the latest version of Thematic won’t help since the bug is in 1.0.3.2. Fortunately, the bug is adressed in the development version on github.

    Try downloading https://github.com/ThematicTheme/Thematic/archive/1.0.3.3-beta2.zip and see if your problem persists. Please report back with your result, so we can investigate further if needed.

    And yes you no longer need to define the thematic compatible body and posts classes. We have moved to filtering wordpress’ default classes, which now will work properly in upcoming 1.0.3.3.

    #2990

    onelittlemoose
    Participant

    I have finally sat down and taken another good long look at this, working with the WordPress core body classes. I have happily gotten the body classes working with WP itself, so this shouldn’t be a problem going forward with Thematic.

    Here is the code,  in case this helps someone else down the road:

    /************** BODY CLASSES *****************/
    
    /* ADD CUSTOM BODY CLASSES &#8211; ON SPECIFIC PAGES */
    add_filter( &#8216;body_class&#8217;, &#8216;add_body_class&#8217; );
    function add_body_class( $classes ) {
    if ( is_page( &#8216;lake-dief&#8217; )) {
    $classes[] = &#8216;lake-dief&#8217;; }
    if ( is_page( &#8216;grasslands&#8217; )) {
    $classes[] = &#8216;grasslands&#8217;; }
    if ( is_page( &#8216;big-muddy&#8217; )) {
    $classes[] = &#8216;big-muddy&#8217;; }
    if ( is_page( array(&#8216;prize-package&#8217;,&#8217;contest-entry-form&#8217;,&#8217;contest-rules&#8217;))) {
    $classes[] = &#8216;prize-package&#8217;; }
    return $classes;
    }
    
    // ADD CATEGORY NICENAMES IN POST AND BODY CLASS
    // <a href="http://codex.wordpress.org/Function_Reference/body_class" rel="nofollow">http://codex.wordpress.org/Function_Reference/body_class</a>
    // THIS IS SO THE INDIVIDUAL POST GETS THE BODY CLASS
    // DON&#8217;T UNDERSTAND WHY THIS  WORKS BUT IT DOES
    function category_id_class($classes) {
    global $post;
    foreach((get_the_category($post->ID)) as $category)
    $classes[] = $category->category_nicename;
    return $classes;
    }
    add_filter(&#8216;post_class&#8217;, &#8216;category_id_class&#8217;);
    add_filter(&#8216;body_class&#8217;, &#8216;category_id_class&#8217;);
    
    // ADD CUSTOM BODY CLASSES &#8211; ON TRIBE EVENTS, BOTH CATEGORY ARCHIVES AND INDIVIDUAL EVENT POST
    // FOR EVENTS CALENDAR PRO PLUGIN
    function tribe_category_id_class($classes) {
    if ($post_type = &#8216;tribe_events&#8217;) {
    if (tribe_event_in_category(&#8216;whats-happening-in-lake-dief&#8217;)) {
    $classes[] = &#8216;lake-dief&#8217;; }
    if (tribe_event_in_category(&#8216;whats-happening-in-grasslands&#8217;)) {
    $classes[] = &#8216;grasslands&#8217;; }
    if (tribe_event_in_category(&#8216;whats-happening-in-big-muddy&#8217;)) {
    $classes[] = &#8216;big-muddy&#8217;; }
    return $classes; }
    }
    add_filter(&#8216;post_class&#8217;, &#8216;tribe_category_id_class&#8217;);
    add_filter(&#8216;body_class&#8217;, &#8216;tribe_category_id_class&#8217;);
    
    /************** END BODY CLASSES *****************/
    
    
    #2993

    onelittlemoose
    Participant

    Oops, I may have spoken too soon. It all works, except … tag archives and search results.

    The body class in a tag archive page takes on an arbitrary body class from the categories. Might not be entirely arbitrary; it almost appears as if it’s taking the class from the category of one of the posts. But the tagged posts are not necessarily all from the same category.  Same thing happens on search results.

    Ideally I’d like the tag archives and the search pages to have no extra body classes. Or alternatively their own separate class, but either way, would like to have some control over it.

    Open to ideas. Perhaps there is something I’ve missed along the way.

    Thanks.

    #2994

    Rob Yardman
    Participant

    This is a problem I’ve been plagued with myself on a couple websites.

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘Body class conflict with The Events Calendar Pro’ is closed to new replies.