您现在的位置是:首页 > 网站制作 > WordpressWordpress

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

杰帅2023-07-20【Wordpress】人已围观

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

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

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

<?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 设置调用文章的总数量;

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

Tags:wordpress教程   文章   置顶

很赞哦! ()

文章评论

本站推荐

站点信息

  • 建站时间:2018-10-24
  • 网站程序:帝国CMS7.5
  • 主题模板《今夕何夕》
  • 文章统计1172篇文章
  • 标签管理标签云
  • 统计数据百度统计
  • 微信公众号:扫描二维码,关注我们