首页 论坛 WordPress最新文章列表中置顶文章靠前显示
帖子详情

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

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

代码放置好之后,可以在网站后台设置置顶文章。方法见:wordpress置顶文章调用与设置

版权:言论仅代表个人观点,不代表官方立场。转载请注明出处:https://www.52diyhome.com/forum/65487.html

发表评论
暂无评论
  • 0 +

    访问总数

  • 0 +

    会员总数

  • 0 +

    资源总数

  • 0 +

    今日发布

  • 0 +

    本周发布

  • 0 +

    运行天数

资源在于分享,创作来源想象