我想在前四篇文章中增加一门课。要在html上这样打印:
<post id="post-1" class="classes first">
<post id="post-2" class="classes second">
<post id="post-3" class="classes third">
<post id="post-4" class="classes fourth">我的圈套:
<?php query_posts('cat=15'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
</div>
<?php endwhile; endif; ?>非常感谢
发布于 2014-05-17 23:33:05
你可以这样做:
<?php query_posts('cat=15'); ?>
<?php $count = 1; ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<div id="post-<?php the_ID(); ?>" class="post<?php echo $count; ?>">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php the_content(); ?>
</div>
<?php $count++; ?>
<?php endwhile; endif; ?>在css中,使用div.post1、div.post2、div.post3和div.post4
发布于 2014-05-18 02:02:51
如果使用的是班级函数,则可以使用post_class筛选器。
add_filter( 'post_class', 'add_class_to_first_four' );
function add_class_to_first_four( $classes ) {
global $wp_query;
$cur = $wp_query->current_post;
if ( 0 == $cur ) $classes[] = 'first';
if ( 1 == $cur ) $classes[] = 'second';
if ( 2 == $cur ) $classes[] = 'third';
if ( 3 == $cur ) $classes[] = 'fourth';
return $classes;
}https://stackoverflow.com/questions/23717060
复制相似问题