WordPress置顶文章类名标签:sticky_class

WordPress模板标签sticky_class用于在The Loop主循环中,如果文章为置顶状态时,则输出类名:sticky,以便于为置顶文章设置特殊样式。

sticky_class( int $post_id = null )

函数参数

$post_id

整数型,默认值:null

指定文章ID,在The Loop主循环中不需要指定。

函数使用示例

在归档页面循环输出文章,置顶文章的容器会加上sticky类。

<?php while( have_posts() ) : the_post(); ?>
	<div class="<?php sticky_class(); ?>">
		......
	</div>
<?php endwhile; ?>

扩展阅读

sticky_class()函数位于:wp-includes/general-template.php

相关函数:

阿里云