Upgrading to v 1.0.3.1 and body_class in functions.php

Home Forums Using Thematic Child Themes Build Your Own Custom Child Themes Upgrading to v 1.0.3.1 and body_class in functions.php

This topic is: not resolved

This topic contains 18 replies, has 5 voices, and was last updated by  Daniel 4 years, 11 months ago.

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #2285

    onelittlemoose
    Participant

    Before upgrading to the new Thematic version want to check that I know what to do on the body_class part in case something breaks.

    Referencing these instructions here:
    http://thematictheme.com/forums/topic/custom-post-type-added-to-body-classpost-class-in-new-version-of-thematic/

    I have a site that contains the following in the functions file

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

    I would just delete the above?

    And then, my filter, which currently says this:

    //WRITING CLASSES TO THE SLUGS
    add_filter(‘thematic_body_class’,’my_class_names’);
    function my_class_names($classes) {
    // add ‘class-name’ to the $classes array
    $classes[] = ‘class-name’;
    // return the $classes array
    return $classes;
    }

    I should rewrite that first line to read instead

    
    add_filter(‘body_class’,’my_class_names’);
    
    

    This should be all I need to do, yes? There shouldn’t be anything in the css that needs to be rewritten.

    Any insights welcome. Thanks.

    #2286

    Scott Nix
    Moderator

    Yes, you are 100% correct.

    For anyone else the snippet above got a little mangled from formatting and I have created a gist for examples of how to add a single class and multiple classes.

    https://gist.github.com/23b0b7a3bd8ffe028e35

    #2288

    Scott Nix
    Moderator

    I didn’t see the CSS part of the question, it should be fine as long as you have the same classes in your custom code, I am pretty sure the body classes Thematic used are identical to the standard WP classes.

    #2291

    helgatheviking
    Moderator

    i did the checks on body_class() versus thematic_body_class() back when we decided to deprecate it.  they are not 100% identical.  some classes might get lost, but there weren’t that many of them and they tended to be obscure…. ie. i had never, ever used them.  switching to body_class() however, gains better native support for post types, taxonomies and post formats instead of constantly playing catch up.  more important now that no one is actively developing this.  afaik.

    any class you lose from thematic_body_class, can just be filtered into body_class… or your CSS can be updated accordingly.

    #2314

    onelittlemoose
    Participant

    Thanks. I deleted and adjusted as per my first post above. It seems though I’m still missing something. I had worked with the body classes to have specific header images for certain posts and their categories, and also groups of pages. It seems the category is working, but not the singular post, and also not the slug for the page.  Here is code excerpt.

    body.slug-great-sandhills #header-box,
    body.category-great-sandhills #header-box,
    body.category-places-to-go-in-great-sandhills #header-box,
    body.s-category-places-to-go-in-great-sandhills #header-box,
    body.category-things-to-do-in-great-sandhills #header-box,
    body.s-category-things-to-do-in-great-sandhills #header-box
    {
          background: url(headers/header_sandhills.jpg) no-repeat;
    }
    

    When I check the source in the respective pages and posts, I see the body class is not there; it’s only on the category archive. So I think I’m missing something. Would these be some of the obscure things you mentioned, helgatheviking?

    Thanks again.

    #2459

    Daniel
    Participant

    When I delete this from my function file:

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

    Then my class not works. I also changed all ‘thematic_body_class’ to ‘body_class’ and still my site is correctly working only if this code:

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

    is active.

    Im completely out of what I should do.

    Is possible say what is have to be changed to make thematic compatible with older version?

    Thx for respond.

    #2461

    Daniel
    Participant

    I tried make it on my own. With 1.0.3.1 we lost some classes as “is-excerpt” and some others if dont use:

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

    Have 3 hours spend on findind which classes missing and trying to filter them back manulay without success… Im little mad about this so I decided For now, Im sticking with depracated ‘THEMATIC_COMPATIBLE_POST_CLASS’ and keep thematic_post_class active.

    Have nice day all who solving same troubles… and keep me updated if you find a way…

    #2462

    Gene (emhr)
    Keymaster

    Hi mdfk,

    Try putting this in your child theme’s functions.php

    add_theme_support(‘thematic_legacy_body_class’);
    add_theme_support(‘thematic_legacy_post_class’);

    That will enable Thematic’s previous classes to filter into the WordPress body_class() and post_class().

    #2466

    Daniel
    Participant

    Thx for advice GENE , but no eefect at all.
    Summary (Im using some user added classes which Im filtering via “thematic_post_class”.):
    CASE 1) comment out (or delete)

    define('THEMATIC_COMPATIBLE_BODY_CLASS', true);
    define('THEMATIC_COMPATIBLE_POST_CLASS', true);

    and meanwhile change all thematic_post_class to post_class
    resume = work partially only – loose for example the is-excerpt class etc…

    CASE 2) Only change all filter hooks names thematic_post_class to post_class
    resume = lost almost half classes

    CASE 3) keep define(“… code in functions.php and keep thematic_post_class = works like charm, like before, but everywhere on web Helga and others writes that constatnts “thematic_post_class” are deprecated and should not be used more…

    So I dont know what to do to be fully only “post_class” compatible. And thank you

    #2467

    Gene (emhr)
    Keymaster

    Ok I see that the constants are still functional. They basically do the add_theme_support for you.

    Which is why you should move toward not using the constants and simply using the add_theme_support function.

    Can you post the code your working with on http://wordpress.pastebin.ca and link to it here?
    Can you list the exact classes that you need in both the body class and post class?

    #2475

    Daniel
    Participant

    Ok I found some objectives, this problem has two solutions:
    A) I observed i need specify is-excerpt class for all excerpts and do not include your legacy constants (becose when I use legacy constants it will overwrite my class which I adding via this filter http://wordpress.pastebin.ca/2248364 )
    B) Use legacy constatnts, obtain class automatically but MUST solve the adding back the format-xxxyyy class …

    nothing is simple… 😀 Thank for cumunicate you must be very kind 🙂 If you can use firefox and firebug to see my code and classes. I will not upload my php content to any web site. Its safety rule:) hope understatnd.
    http://www.danielkral.cz

    If you can tell me how prevent to ‘thematic_legacy_post_class’ constatnt delete my class format-xxxyyy OR how detect is post is excerpt and add it class ‘is-excerpt’ it will be great.

    I know this isnt hot issue, for example as “making money” 😀 so thank for again your time…

    #2479

    Daniel
    Participant

    SOLVED by version A !!! And now proudly presenting 😀 :
    you can detect excerpt and add class to it by :

    function dkexcerpt_class( $classes = array() ) {
     global $thematic_content_length;
     if ( strtolower($thematic_content_length) == ‘excerpt’ ){ $classes[] = ‘is-excerpt’; }
     return $classes;
     }
     add_filter( ‘post_class’, ‘dkexcerpt_class’ );

    Nothing else used. Only removed “thematic_” prefix from thematic_post_class and removed

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

    Thats all.
    Im missing SLUG-classes but it could be replaced by ID classes. And I think add it manualy would be fun 😀

    Many thanks GENE for bring me on the right way! 🙂

    #2482

    Gene (emhr)
    Keymaster

    Here’s what I suggest.

    Dont define any of the THEMATIC_COMPATIBLE_* constants
    Use the following code:

    add_theme_support(‘thematic_legacy_post_class’);
    
    function dk_thematic_post_format_class( $classes ) {
     $format = get_post_format();
     if ( ” == $format ){ $format = ‘standard’; }
     $classes[] = ‘format-‘ . $format;
     return $classes;
     }
     add_filter( ‘thematic_post_class’, ‘dk_thematic_post_format_class’);
    
    

     

    The big difference to the first parameter of add_filter() needs to be ‘thematic_post_class’. That is what make both of the filters to work together.

    #2483

    Gene (emhr)
    Keymaster

    And you would do something similar for the body classes….

    add_theme_support(‘thematic_legacy_body_class’);
    function childtheme_body_class( $classes ) {
     $classes[] = ‘my-class’;
     return $classes;
     }
     add_filter( ‘thematic_body_class’, ‘childtheme_body_class’);
    
    #2484

    Daniel
    Participant

    Today I updgraded to v 1.0.3.2 so we will have new issues 😀 -joke

    Filter should be only “body_class” not “thematic_body_class” isnt? As Helga wrote. …?! my english not so good Im from europe.

    But thanks for coop , i read you many times before, Gene, Helgatheviking, and others forums what appears when I was tried solve some problem via google. It was really hard to find which classes i used was deprecated. So if I identified them (approx almost! whole weekend ? ), I could make some other reserch in code to find the way. And after years on internet I relalized that forums are very good to find what you need. see the results on http://www.danielkral.cz .

Viewing 15 posts - 1 through 15 (of 19 total)

The topic ‘Upgrading to v 1.0.3.1 and body_class in functions.php’ is closed to new replies.