有的時候我們會在特殊位置顯示一些網站的置頂文章,那麼我們需要如何操作呢?

首先設置幾篇文章為置頂文章,這裏要説明的是,設置置頂文章不需要在文章編輯頁面,而是文章的快速編輯裏有置頂按鈕

然後,在需要顯示置頂文章的地方,插入下面的代碼,即可調用 WordPress 獲取指定文章的方法

20131209165348

  1. <ul>   
  2.             <?php $sticky = get_option('sticky_posts'); rsort( $sticky );  
  3.                     $sticky = array_slice$sticky, 0, 2);query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );   
  4.                 if (have_posts()) :while (have_posts()) : the_post();       
  5.             ?>   
  6.             <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></li>   
  7.             <?php endwhileendif; ?>   
  8.         </ul>