WordPress.org

Make WordPress Core

Changeset 8638


Ignore:
Timestamp:
08/13/2008 07:09:08 PM (10 years ago)
Author:
ryan
Message:

Add post_class() template function for emitting standard classes for post div. see #7457

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-content/themes/classic/index.php

    r8637 r8638  
    77<?php the_date('','<h2>','</h2>'); ?>
    88
    9 <div class="post<?php sticky_class(); ?>" id="post-<?php the_ID(); ?>">
     9<div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    1010     <h3 class="storytitle"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h3>
    1111    <div class="meta"><?php _e("Filed under:"); ?> <?php the_category(',') ?> &#8212; <?php the_tags(__('Tags: '), ', ', ' &#8212; '); ?> <?php the_author() ?> @ <?php the_time() ?> <?php edit_post_link(__('Edit This')); ?></div>
  • trunk/wp-content/themes/default/index.php

    r8637 r8638  
    77        <?php while (have_posts()) : the_post(); ?>
    88
    9             <div class="post<?php sticky_class(); ?>" id="post-<?php the_ID(); ?>">
     9            <div <?php post_class() ?> id="post-<?php the_ID(); ?>">
    1010                <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    1111                <small><?php the_time('F jS, Y') ?> <!-- by <?php the_author() ?> --></small>
  • trunk/wp-includes/post-template.php

    r8637 r8638  
    159159    $post = &get_post( $id );
    160160    return ( !empty( $post->post_excerpt ) );
     161}
     162
     163/**
     164 * Echo the classes for the post div
     165 *
     166 * {@internal Missing Long Description}}
     167 *
     168 * @package WordPress
     169 * @subpackage Post
     170 * @since 2.7
     171 *
     172 @ param string $class One or more classes to add to the class list
     173 * @param int $post_id An optional post ID
     174 */
     175function 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);
     186
     187    echo 'class="' . $classes . '"';
    161188}
    162189
Note: See TracChangeset for help on using the changeset viewer.