有些時候我們需要呼叫 WordPress 置頂文章並單獨顯示出來,可以透過 WP_Query 來實現,程式碼如下:
- <?php
- $args = array(
- 'posts_per_page' => -1,
- );
- $sticky_posts = new WP_Query( $args );
- while ( $sticky_posts->have_posts() ) : $sticky_posts->the_post();?>
- <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a>
- <?php endwhile; wp_reset_query();?>