前幾天在做一個 WordPress 主題想把最新文章列表和置頂文章列表分開顯示,可在調用最新文章列表時發現,如果 WordPress 網站有置頂文章,那 麼最新文章列表也會把博客的置頂文章顯示在最前面,但是可以通過設置置頂文章的參數 caller_get_posts 排除列表中的最新文章。
- <?php
- $post_num = 10;
- $args=array(
- 'paged' => $paged,
- 'posts_per_page' => $post_num
- query_posts($args);
- if ( have_posts() ) : while ( have_posts() ) : the_post();
- <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
- endwhile; else: endif; wp_reset_query();?>
主要代碼來自 WordPress 中文主題站