WordPress: Post ID Custom CSS

I am wanting to create a custom design for indivudual posts on my wordpress.org blog.

Is it possible to modify the indivdual posts css code without affecting any other posts design?

Read More

You can do this with categories by creating a new PHP document for the categories ID, but I can’t get this to work with post ID’s.

Any help would be awesome. Thanks.

Related posts

Leave a Reply

2 comments

  1. You can create new post template files for each category? Add this into single.php to conditionally load them:

    $post = $wp_query->post;
    
    if ( in_category('2') ) {
    
    include(TEMPLATEPATH . '/single-blog.php'); } 
    
    elseif ( in_category('15') ) {
    
    include(TEMPLATEPATH . '/single-photography.php'); } 
    
    elseif ( in_category('18') ) {
    
    include(TEMPLATEPATH . '/single-video.php'); } 
    
    else {
    
    include(TEMPLATEPATH . '/single-default.php');
    
    }
    

    Then you wouldn’t need tocreate CPTs or condtionally style the body tag. Just simple stand-alone templates for each category, tag etc.

    UPDATE:
    I found this when digging through the awesome Bones WP theme.

    <article id="post-<?php the_ID(); ?>" <?php post_class('clearfix'); ?>
    

    Check out what post_class() does for specific post and category styling.

  2. To answer your exact question, on the post’s body tag is a unique class for THAT post id.

    For example http://eyespeak.com/blog/2013/08/friday-favorites-823/

    If you inspect the body tag it has the class of postid-10532

    Using that class, you can apply page/post/id/template specific CSS.

    .postid-10532 {
        background: red;
        color: lime;
    }
    .postid-10532:before {
        content: 'HERE IS SOME BEFORE CONTENT';
    }
    

    This is all done via wordpress’s bodyclass function