有些时候我们需要调用 WordPress 置顶文章并单独显示出来,可以通过 WP_Query 来实现,代码如下:
<?php $args = array( 'posts_per_page' => -1, 'post__in' => get_option( 'sticky_posts' ) ); $sticky_posts = new WP_Query( $args ); while ( $sticky_posts->have_posts() ) : $sticky_posts->the_post();?> <li> <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> </li> <?php endwhile; wp_reset_query();?>
时事新闻
2014/12/16 上午9:21文章写的很不错啊,碰巧是我需要的。哈哈。