有些時候我們需要調用 WordPress 置頂文章並單獨顯示出來,可以通過 WP_Query 來實現,代碼如下:

  1. <?php  
  2. $args = array(  
  3. 'posts_per_page' => -1,  
  4. );  
  5. $sticky_posts = new WP_Query( $args );  
  6. while ( $sticky_posts->have_posts() ) : $sticky_posts->the_post();?>  
  7. <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>  
  8. <?php endwhile; wp_reset_query();?>