<?php $cat = get_the_category();
foreach($cat as $key=>$category){
$cat = $category->term_id;
}
$sticky = get_option('sticky_posts');
query_posts( array('post__in' => $sticky,'caller_get_posts' =>1,'offset'=> 0,'cat'=>$cat,'showposts'=>9));
static $case_num=0;
while (have_posts()) : the_post(); ?>
<!--置顶文章-->
<li>置顶文章<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php $case_num++;
endwhile; wp_reset_query();
$case_num=9-$case_num;//
query_posts( array( 'post__not_in' => get_option( 'sticky_posts'),'cat'=>$cat,'showposts'=>$case_num ));
while (have_posts()) : the_post();
?>
<!--非置顶文章-->
<li>非置顶<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; wp_reset_query(); ?>
在wordpress模板制作过程中,有时我们会用到置顶文章与非置顶文章分开调用的情况,这段代码完美解决了,置顶文章与非置顶文章的调用问题。