在wordpress最新文章列表中排除置顶文章
网站文章 2026-09-21 08:27:42 4 0

前阵子在弄一个wordpress主题想把最新文章列表和置顶文章列表分开显示,可在调用最新文章列表时发现,如果wordpress博客有置顶文章,那么最新文章列表也会把博客的置顶文章显示在最前面,但是可以通过设置置顶文章的参数caller_get_posts排除列表中的最新文章。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
    $post_num = 10; // 显示文章的数量.
    $args=array(
    'post_status' => 'publish',
    'paged' => $paged,
    'caller_get_posts' => 1,
    '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>
<?php endwhile; else: endif; wp_reset_query();?>

主要代码来自wordpress中文论坛!

文章说明
本文标签:
©版权声明
本站提供的一切软件、教程和游戏辅助仅限用于娱乐和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络收集,版权争议与本站无关。如有侵权请邮件与我们联系处理。敬请谅解!6594404@qq.com