wordpress获取置顶文章的方法

2019年12月18日19:22:28 发表评论 热度443 ℃

有的时候我们会在特殊位置显示一些网站的置顶文章,那么我们需要如何操作呢?

首先设置几篇文章为置顶文章,这里要说明的是,设置置顶文章不需要在文章编辑页面,而是文章的快速编辑里有置顶按钮

然后,在需要显示置顶文章的地方,插入下面的代码,即可调用wordpress获取指定文章的方法
20131209165348

  1. <ul>   
  2.             <?php $sticky = get_option('sticky_posts'); rsort( $sticky );  
  3.                     $sticky = array_slice$sticky, 0, 2);query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );   
  4.                 if (have_posts()) :while (have_posts()) : the_post();       
  5.             ?>   
  6.             <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></li>   
  7.             <?php endwhileendif; ?>   
  8.         </ul>  
瓜皮猪

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: