Make WordPress Core


Ignore:
Timestamp:
08/13/2008 09:58:06 PM (15 years ago)
Author:
ryan
Message:

Add more classes to post_class(). see #7457

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/post-template.php

    r8639 r8641  
    174174 */
    175175function post_class( $class = '', $post_id = null ) {
    176 
    177     $classes = 'post';
    178 
    179     if ( is_sticky($post_id) )
    180         $classes .= ' sticky';
    181 
    182     if ( !empty($class) )
    183         $classes .= ' ' . $class;
    184 
    185     $classes = apply_filters('post_class', $classes, $class, $post_id);
     176    $post = get_post($post_id);
     177
     178    $classes[] = $post->post_type;
     179
     180    if ( is_sticky($post->ID) )
     181        $classes[] = 'sticky';
     182
     183    // hentry for hAtom compliace
     184    $classes[] = 'hentry';
     185
     186    // Categories
     187    foreach ( (array) get_the_category($post->ID) as $cat ) {
     188        if ( empty($cat->slug ) )
     189            continue;
     190        $classes[] = 'category-' . $cat->slug;
     191    }
     192
     193    // Tags
     194    foreach ( (array) get_the_tags($post->ID) as $tag ) {
     195        if ( empty($tag->slug ) )
     196            continue;
     197        $classes[] = 'tag-' . $tag->slug;
     198    }
     199
     200    if ( !empty($class) ) {
     201        $class = preg_split('#\s+#', $class);
     202        $classes = array_merge($classes, $class);
     203    }
     204
     205    // Separates classes with a single space, collates classes for post DIV
     206    $classes = join(' ', apply_filters('post_class', $classes, $class, $post_id));
    186207
    187208    echo 'class="' . $classes . '"';
Note: See TracChangeset for help on using the changeset viewer.