前几天在做一个 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 中文主题站