有些時候我們需要調用 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();?>