我要投稿 | 网站地图 WordPress建站学习平台
WordPress教程网
热门标签: wordpress教程 wordpress函数 wordpress WordPress建站 wordpress插件

图文教程

当前位置:首页> 图文教程

WordPress最新文章列表中置顶文章靠前显示

发布:WordPress教程网   发布时间: 2023-02-16  游览次数:32次

在做网站时,有些版块需要调用某个栏目的文章列表,并且要求后台设置的置顶文章靠前显示。如下图:

怎么实现在调用最新文章列表中置顶文章靠前显示呢?代码如下:

<?php
     $sticky = get_option('sticky_posts');
      query_posts( array('post__in' => $sticky,'caller_get_posts' =>1,'cat'=>25,'showposts'=>6));
       static $case_num=0;
     while (have_posts()) : the_post();  ?>
     <!--置顶文章-->
                        <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
<?php $case_num++;
     endwhile; wp_reset_query();  
          $case_num=6-$case_num;//
          query_posts( array( 'post__not_in' => get_option( 'sticky_posts'),'cat'=>25,'showposts'=>$case_num ));
       while (have_posts()) : the_post();
?>
<!--非置顶文章-->
    <li><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>

      <?php endwhile; wp_reset_query(); ?>

代码解释:

'cat'=>25 设置调用的分类目录ID号;'showposts'=>6 设置调用文章的总数量;

代码放置好之后,可以在网站后台设置置顶文章。

本文版权归原作者所有,转载请注明原文来源出处, WordPress教程网 感谢您的支持!

本文链接: http://www.wpcn.net/877.html

WordPress教程网
WordPress教程网
相关内容