wordpress首页调用置顶文章列表

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

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

wordpress首页调用置顶文章列表代码如下:

<ul>   
     <?php $sticky = get_option('sticky_posts'); rsort( $sticky );  
                    $sticky = array_slice( $sticky, 0, 2);query_posts( array( 'post__in' => $sticky, 'caller_get_posts' => 1 ) );   
                if (have_posts()) :while (have_posts()) : the_post();       
            ?>   
            <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark"><?php the_title(); ?></a></li>   
            <?php endwhile; endif; ?>   
</ul>  

 

posted @ 2018-06-24 19:03  觉白  阅读(308)  评论(0)    收藏  举报