前幾天在做一個 WordPress 主題想把最新文章列表和置頂文章列表分開顯示,可在調用最新文章列表時發現,如果 WordPress 網站有置頂文章,那 麼最新文章列表也會把博客的置頂文章顯示在最前面,但是可以通過設置置頂文章的參數 caller_get_posts 排除列表中的最新文章。

  1. <?php
  2. $post_num = 10; 
  3.     $args=array(
  4.     'paged' => $paged,
  5.     'posts_per_page' => $post_num
  6.     query_posts($args);
  7.     if ( have_posts() ) : while ( have_posts() ) : the_post();
  8.     <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
  9. endwhile; elseendif; wp_reset_query();?>

主要代碼來自 WordPress 中文主題站