Add more classes to post_class(). see #7457

git-svn-id: http://svn.automattic.com/wordpress/trunk@8641 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2008-08-13 21:58:06 +00:00
parent 9a95395188
commit 9e05ca767a
4 changed files with 30 additions and 9 deletions

View File

@ -28,7 +28,7 @@
</div>
<?php while (have_posts()) : the_post(); ?>
<div class="post">
<div <?php post_class() ?>>
<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<small><?php the_time('l, F jS, Y') ?></small>

View File

@ -14,7 +14,7 @@
<?php while (have_posts()) : the_post(); ?>
<div class="post">
<div <?php post_class() ?>>
<h3 id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<small><?php the_time('l, F jS, Y') ?></small>

View File

@ -9,7 +9,7 @@
<div class="alignright"><?php next_post_link('%link &raquo;') ?></div>
</div>
<div class="post" id="post-<?php the_ID(); ?>">
<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
<h2><?php the_title(); ?></h2>
<div class="entry">

View File

@ -173,16 +173,37 @@ function has_excerpt( $id = 0 ) {
* @param int $post_id An optional post ID
*/
function post_class( $class = '', $post_id = null ) {
$post = get_post($post_id);
$classes = 'post';
$classes[] = $post->post_type;
if ( is_sticky($post_id) )
$classes .= ' sticky';
if ( is_sticky($post->ID) )
$classes[] = 'sticky';
if ( !empty($class) )
$classes .= ' ' . $class;
// hentry for hAtom compliace
$classes[] = 'hentry';
$classes = apply_filters('post_class', $classes, $class, $post_id);
// Categories
foreach ( (array) get_the_category($post->ID) as $cat ) {
if ( empty($cat->slug ) )
continue;
$classes[] = 'category-' . $cat->slug;
}
// Tags
foreach ( (array) get_the_tags($post->ID) as $tag ) {
if ( empty($tag->slug ) )
continue;
$classes[] = 'tag-' . $tag->slug;
}
if ( !empty($class) ) {
$class = preg_split('#\s+#', $class);
$classes = array_merge($classes, $class);
}
// Separates classes with a single space, collates classes for post DIV
$classes = join(' ', apply_filters('post_class', $classes, $class, $post_id));
echo 'class="' . $classes . '"';
}